Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Lock a file for reading when uploading it to FTP

Lock a file for reading when uploading it to FTP

Scheduled Pinned Locked Moved C#
help
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thoru
    wrote on last edited by
    #1

    Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx

    W L 2 Replies Last reply
    0
    • T thoru

      Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, If you're using Open-method on File class use FileShare.None for share parameter. This should prevent opening the file elsewhere. Mika

      1 Reply Last reply
      0
      • T thoru

        Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        How does the consumer process know there is a file to process? And does the consumer use FTP to download the file, or is it on the machine your producer is uploading to? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        T 1 Reply Last reply
        0
        • L Luc Pattyn

          How does the consumer process know there is a file to process? And does the consumer use FTP to download the file, or is it on the machine your producer is uploading to? :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Voting for dummies? No thanks. X|


          T Offline
          T Offline
          thoru
          wrote on last edited by
          #4

          The consumer searches the ftp for a list of files with a given extension. (but it can also grab all the files from ftp, regardless of the extension. This part is configurable)

          L 1 Reply Last reply
          0
          • T thoru

            The consumer searches the ftp for a list of files with a given extension. (but it can also grab all the files from ftp, regardless of the extension. This part is configurable)

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Here are some ways to consider: 1. have the consumer wait for a signal, and once it receives the signal make a list of available files, then signal back to the producer; in between the consumer should not start creating new files. 2. have the producer use a fake extension, and once the file is uploaded, have it rename the extension; 3. have the producer a file, and once the file is uploaded, have it signal the consumer while mentioning the file name. As for signal, you could use anything available, including the creation and deletion of a file that simply contains a filename. My favorite would be 3, i.e. producer creates a file say file1.ext1, then it creates file "currenttime.signal" containing the text "file1.ext1"; consumer would find all signal files, read them, delete them, and process the file mentioned in them. And I would use yyyyMMdd_HHmmss format for currenttime, so the signal files have identical alphabetical and chronological order. PS: if you are afraid two files need could be generated in the same second, just add a 2-second delay in the producer code! :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            T 1 Reply Last reply
            0
            • L Luc Pattyn

              Here are some ways to consider: 1. have the consumer wait for a signal, and once it receives the signal make a list of available files, then signal back to the producer; in between the consumer should not start creating new files. 2. have the producer use a fake extension, and once the file is uploaded, have it rename the extension; 3. have the producer a file, and once the file is uploaded, have it signal the consumer while mentioning the file name. As for signal, you could use anything available, including the creation and deletion of a file that simply contains a filename. My favorite would be 3, i.e. producer creates a file say file1.ext1, then it creates file "currenttime.signal" containing the text "file1.ext1"; consumer would find all signal files, read them, delete them, and process the file mentioned in them. And I would use yyyyMMdd_HHmmss format for currenttime, so the signal files have identical alphabetical and chronological order. PS: if you are afraid two files need could be generated in the same second, just add a 2-second delay in the producer code! :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Voting for dummies? No thanks. X|


              T Offline
              T Offline
              thoru
              wrote on last edited by
              #6

              Thanks Luc. The signal idea has crossed my mind, but not in such a superb manner:). I was afraid i would have to modify quite a lot, and that is not far from truth. I retrospective, the whole architecture of the program should be reconsidered:D. Hopefully i'll have the time to do just that, and then i will implement your solution. Thx all.

              L 1 Reply Last reply
              0
              • T thoru

                Thanks Luc. The signal idea has crossed my mind, but not in such a superb manner:). I was afraid i would have to modify quite a lot, and that is not far from truth. I retrospective, the whole architecture of the program should be reconsidered:D. Hopefully i'll have the time to do just that, and then i will implement your solution. Thx all.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                You're welcome. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Voting for dummies? No thanks. X|


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups