多重下载/平行的FTP使用C#上传 [英] Multiple Download/Upload parallely in FTP using C#

查看:140
本文介绍了多重下载/平行的FTP使用C#上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的多重下载/使用C#不使用的FtpWebRequest在FTP上传平行。
我已经写了我的自定义代码,当我试图同时下载两个文件第一个获得下载正确的,而第二个显示大小为0 KB(也下载)。

I want to do Multiple Download/Upload parallely in FTP using C# without using 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).

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....

推荐答案

戴维说,你需要单独的实例您ftpCommand类。考虑使用BackgroundWorker的在后台(异步)运行命令。

As Dave said, you'd need separate instances of your ftpCommand class. Look into use the BackgroundWorker to run the commands in the background (asynchronously).

这篇关于多重下载/平行的FTP使用C#上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆