【问题标题】:Multiple threads uploading files to filezilla ftp server returns error 550 File unavailable多个线程将文件上传到 filezilla ftp 服务器返回错误 550 文件不可用
【发布时间】:2011-12-13 14:55:44
【问题描述】:

Problem: ftp 一次只上传一个文件时,文件上传正常,但是当我使用多个后台工作人员将文件上传到 ftp 服务器时出现异常:

  • ex {"远程服务器返回错误:(550) 文件不可用 (例如,找不到文件,无法访问)。”} System.Exception {System.Net.WebException}

并且只有部分文件被上传。我很确定文件在该位置退出,实际上在另一个运行中,它抱怨的文件不存在已下载,但错误转移到另一个文件上。

Code Description: 在下面的代码中,我正在从一个 ftp 服务器下载文件并将其放在另一台服务器上。此代码位于 BackgroundsWorker_DoWork 方法中。后台工作人员正在循环内创建。

void imageDownloadWorker_DoWork(object sender, DoWorkEventArgs e)
        {
           string[] ftpInfo = (string[])e.Argument;
            try
            {

                ///////////////////////////Downloading///////////////////////////////////////
                string uri = String.Format("ftp://{0}/{1}/images/{2}", ftpInfo[1], ftpInfo[2], ftpInfo[5]);

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.UseBinary = true;
            request.Credentials = new NetworkCredential(ftpInfo[3], ftpInfo[4]);

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Stream ftpStream = response.GetResponseStream();

            long cl = response.ContentLength;
            int bufferSize = 4096;
            int readCount = 0;
            byte[] buffer = new byte[bufferSize];
            MemoryStream memStream = new MemoryStream();
            readCount = ftpStream.Read(buffer, 0, bufferSize);
            while (readCount > 0)
            {
                memStream.Write(buffer, 0, readCount);
                readCount = ftpStream.Read(buffer, 0, bufferSize);
            }
            response.Close();
            ///////////////////////////Uploading///////////////////////////////////////
            string uri1 = String.Format("ftp://{0}/{1}/{2}", "127.0.0.1", string.Empty, ftpInfo[5]);
            FtpWebRequest request1 = (FtpWebRequest)WebRequest.Create(uri1);
            request1.Credentials = new NetworkCredential("user", "password");
            request1.KeepAlive = false;
            request1.Method = WebRequestMethods.Ftp.UploadFile;
            request1.UseBinary = true;
            request1.ContentLength = memStream.Length;
            int buffLength = 4096;
            byte[] buff = new byte[buffLength];
            int contentLen;

            // Stream to which the file to be upload is written
            Stream strm = request1.GetRequestStream();
            memStream.Seek(0, SeekOrigin.Begin);
            contentLen = memStream.Read(buff, 0, buffLength);
            // Till Stream content ends
            while (contentLen != 0)
            {
                // Write Content from the file stream to the FTP Upload Stream
                strm.Write(buff, 0, contentLen);
                contentLen = memStream.Read(buff, 0, buffLength);
            }

            // Close the file stream and the Request Stream
            strm.Close();
            ftpStream.Close();
            memStream.Close();

        }
        catch(Exception ex)
        {
            MessageBox.Show("While Downloading File " + ftpInfo[5] + " " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            e.Result = null;
            return;
        }

Related Thread

Edit: 在 File Zilla Server 中有一个选项 General Settings>Perfomance Settings>Number of Threads 我已将其设置为 20 它没有任何区别。

【问题讨论】:

标签: c# .net multithreading exception ftp


【解决方案1】:

您的代码可能没有问题。该错误是权限错误。

【讨论】:

  • 这并不是真正的权限错误,但你是对的,我的代码没有任何问题。
  • 很酷,至少你可以确信你写的代码很好。抱歉,我无法为你提供正确的答案。谢谢
【解决方案2】:

在黑暗中完成刺,但是上传目标服务器是否有每个IP限制的连接?如果是这样,您可能会因为超出单个 IP 地址的并发连接限制而犯规。

【讨论】:

  • 在 File Zill Server 中有一个选项 General Settings>Perfomance Settings>Number of Threads 我已将其设置为 20,但没有任何区别。
  • 我不熟悉 File Zill(a?) 服务器,但是服务器运行的线程数和每个客户端 IP 允许的并发连接数是两个不同的东西,假设 File Zill 甚至有并发连接数限制。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
  • 2010-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多