[英]Multiple Download/Upload parallely in FTP using C#
I want to do Multiple Download/Upload parallely in FTP using C# without using FTPWebRequest. 我想使用C#在FTP中并行执行多个下载/上传,而不使用FTPWebRequest。 I have written my custom code and when i try to download two files simultaneously first one get download properly while second one shows size as 0 KB(it also downloads).
我已经编写了自定义代码,当我尝试同时下载两个文件时,第一个文件正确下载,而第二个文件显示为0 KB(它也会下载)。
public void sendCommand(String command, params string[] strfilename)
{
if (command == "RETR ") //Downloading file from Server
{
FileStream output = null;
if (!File.Exists(strfilename[0]))
output = File.Create(strfilename[0]);
else
output = new FileStream(strfilename[0] , FileMode.Open);
command = "RETR " + strfilename[0];
Byte[] cmdBytes = Encoding.ASCII.GetBytes((command + "\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
Socket csocket = createDataSocket();
DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
while (timeout > DateTime.Now)
{
this.bytes = csocket.Receive(buffer, buffer.Length, 0);
output.Write(this.buffer, 0, this.bytes);
if (this.bytes <= 0)
{
break;
}
}
// this.BinaryMode = true;
output.Close();
if (csocket.Connected) csocket.Close();
this.readResponse();
MessageBox.Show("File Downloaded successfully");
else if....so on
}
}
In my main method i do like this: 在我的主要方法中,我这样做:
ftpcommand.sendCommand("RETR ","RMSViewer.xml"); //Downloading from Server
ftpcommand.sendCommand("RETR ","cms.xml");//Downloading from Server
Any code snippet.... 任何代码段...
How are you issuing your requests simultaneously? 您如何同时发出请求?
Threaded? 穿线了吗?
If so - you may want to ensure you're creating separate instances of your "ftpcommand" class. 如果是这样-您可能要确保要创建“ ftpcommand”类的单独实例。
I think we'll need more information to be able to help you :) 我认为我们需要更多信息才能为您提供帮助:)
As Dave said, you'd need separate instances of your ftpCommand class. 正如Dave所说,您需要ftpCommand类的单独实例。 Look into use the BackgroundWorker to run the commands in the background (asynchronously).
查看使用BackgroundWorker在后台运行命令(异步)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.