簡體   English   中英

使用C#在FTP中並行進行多個下載/上傳

[英]Multiple Download/Upload parallely in FTP using C#

我想使用C#在FTP中並行執行多個下載/上傳,而不使用FTPWebRequest。 我已經編寫了自定義代碼,當我嘗試同時下載兩個文件時,第一個文件正確下載,而第二個文件顯示為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

    }
}

在我的主要方法中,我這樣做:

ftpcommand.sendCommand("RETR ","RMSViewer.xml"); //Downloading from Server
ftpcommand.sendCommand("RETR ","cms.xml");//Downloading from Server  

任何代碼段...

您如何同時發出請求?

穿線了嗎?

如果是這樣-您可能要確保要創建“ ftpcommand”類的單獨實例。

我認為我們需要更多信息才能為您提供幫助:)

正如Dave所說,您需要ftpCommand類的單獨實例。 查看使用BackgroundWorker在后台運行命令(異步)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM