In my scenario, users are able to upload zip files to a.example.com
I would love to create a "daemon" which in specified time intervals will move-transfer any zip files uploaded by the users from a.example.com
to b.example.com
From the info i gathered so far,
- The daemon will be an .ashx generic handler.
- The daemon will be triggered at the specified time intervals via a plesk cron job
- The daemon (thanks to SLaks) will consist of two FtpWebRequest's (One for reading and one for writing).
So the question is how could i implement step 3?
- Do i have to read into to a memory() array the whole file and try to write that in
b.example.com
? - How could i write the info i read to
b.example.com
? - Could i perform reading and writing of the file at the same time?
No i am not asking for the full code, i just can figure out, how could i perform reading and writing on the fly, without user interaction.
I mean i could download the file locally from a.example.com
and upload it at b.example.com
but that is not the point.
To answer your questions - yes you can read and write the files at the same time.
You can open an
FTPWebRequest
to ServerA and aFTPWebRequest
to ServerB. On theFTPWebRequest
to serverA you would request the file, and get theResponseStream
. Once you have theResponseStream
, you would read a chunk of bytes at a time, and write that chunck of bytes to the serverBRequestStream
.The only memory you would be using would be the
byte[]
buffer in your read/write loop. Just keep in mind though that the underlying implementation ofFTPWebRequest
will download the complete FTP file before returning the response stream.Similarly, you cannot send your
FTPWebRequest
to upload the new file until all bytes have been written. In effect, the operations will happen synchronously. You will callGetResponse
which won't return until the full file is available, and only then can you 'upload' the new file.References:
FTPWebRequest