[英]how to move files from one ftp to another
I need to move files from one ftp to another (currently using ftpwebrequest) both requiring authentication and have different settings (timeout, ascii, active etc). 我需要将文件从一个ftp移动到另一个(当前使用ftpwebrequest),都需要身份验证,并且设置不同(超时,ascii,活动等)。 Is downloading files from one to a local server and then uploading to the other significant slower than just copying the files (if that exists even, how would you do it, renameto?). 将文件从一个文件下载到本地服务器,然后再上传到另一个服务器,这比仅复制文件要慢得多(如果该文件甚至存在,您将如何处理,重命名为?)。 It feels like it should be faster but I'm not sure, I have no understanding of file copying or downloading. 感觉它应该更快,但是我不确定,我对文件复制或下载不了解。
they are all .txt or .csv and mostly around 3-10 mb each so quite a bit of data 它们都是.txt或.csv文件,每个文件的大小都在3到10 mb左右,因此相当多的数据
Some time we need to download, upload file from FTP server. 一段时间我们需要从FTP服务器上载文件。 Here is some good example for FTP operation in C#. 这是C#中FTP操作的一些好例子。 You can use this. 您可以使用它。 It will help you to make a C# program to full fill your requirements. 这将帮助您制作一个C#程序来完全满足您的要求。
File Download from FTP Server 从FTP服务器下载文件
public void DownloadFile(stringHostURL, string UserName, string Password, stringSourceDirectory, string FileName, string LocalDirectory)
{
if(!File.Exists(LocalDirectory + FileName))
{
try
{
FtpWebRequestrequestFileDownload = (FtpWebRequest)WebRequest.Create(HostURL + “/” + SourceDirectory + “/” + FileName);
requestFileDownload.Credentials = new NetworkCredential(UserName, Password);
requestFileDownload.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponseresponseFileDownload = (FtpWebResponse)requestFileDownload.GetResponse();
StreamresponseStream = responseFileDownload.GetResponseStream();
FileStreamwriteStream = new FileStream(LocalDirectory + FileName, FileMode.Create);
intLength = 2048;
Byte[] buffer = new Byte[Length];
intbytesRead = responseStream.Read(buffer, 0, Length);
while(bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
responseStream.Close();
writeStream.Close();
requestFileDownload = null;
responseFileDownload = null;
}
catch(Exception ex)
{
throwex;
}
}
}
Hope it will help you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.