如何做一个服务器到服务器的文件传输,无需任何用户互动? [英] How To Do a Server To Server File Transfer without any user interaction?
问题描述
在我的方案,用户可以压缩文件上传到 a.example.com
In my scenario, users are able to upload zip files to a.example.com
我很想创造一个守护程序从 a.example.com
这在指定的时间间隔将移动传输由用户上传的任何zip文件 b.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,
- 的守护进程将是一个ashx的通用处理器。
- 的守护进程将在指定的时间间隔通过的Plesk cron作业 触发
- 的守护进程(感谢 SLaks )将包含两个的FtpWebRequest的(一个用于读取,一个用于写入)。
- 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).
所以,问题是我怎么能实现第3步?
So the question is how could i implement step 3?
- 请我一定要读入到存储器()数组整个文件,并尝试写在
b.example.com
? - 我怎么能写我读
b.example.com
的信息? - 我可以在同一时间进行阅读和文件的写?
没有我不要求为全面code,我只是可以计算出,我怎么可能执行读取和动态写作,无需用户交互。
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.
我的意思是我可以从 a.example.com
本地下载文件,并上传在 b.example.com
但是这不是重点。
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.
您可以打开的FtpWebRequest
来ServerA和一个的FtpWebRequest
到ServerB。在的FtpWebRequest
来SERVERA你需要一个文件,并获得 ResponseStream
。一旦你的 ResponseStream
,你会一次读取的字节块,并写入字节到serverB上 RequestStream $ C那chunck $ C>。
You can open an FTPWebRequest
to ServerA and a FTPWebRequest
to ServerB. On the FTPWebRequest
to serverA you would request the file, and get the ResponseStream
. Once you have the ResponseStream
, you would read a chunk of bytes at a time, and write that chunck of bytes to the serverB RequestStream
.
您将使用将是字节[]
在读/写循环缓冲区中的唯一的记忆。只要记住,虽然底层的实施的FtpWebRequest
将返回响应流之前下载完整的FTP文件。
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 of FTPWebRequest
will download the complete FTP file before returning the response stream.
同样,你不能把你的的FtpWebRequest
,直到所有字节都被写入新文件上传。实际上,操作将同步发生。你会调用的GetResponse
,不会返回,直到完整的文件可用,然后才可以上传的新文件。
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 call GetResponse
which won't return until the full file is available, and only then can you 'upload' the new file.
参考文献:
这篇关于如何做一个服务器到服务器的文件传输,无需任何用户互动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!