【问题标题】:FTP file upload on Local Network C#本地网络 C# 上的 FTP 文件上传
【发布时间】:2016-07-28 09:41:43
【问题描述】:

我在 FTP 服务器上上传文件时遇到问题。 当我在我的计算机(127.0.0.1)上运行 FileZilla 服务器时,图像文件已成功上传。但是我在同一网络中的另一台计算机上运行 FileZilla 服务器。(10.0.1.25)。我可以在这台计算机上创建目录,但我无法上传图像文件,尽管我的用户可以完全控制这台计算机。

 public bool Upload(Stream srcStream, string dstFilePath)
    {
         Create FtpWebRequest object from the Uri provided
        FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(serverUri + dstFilePath));
        reqFTP.Credentials = credential;
        reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
        reqFTP.UseBinary = true;
        reqFTP.Proxy = null;
        reqFTP.UsePassive = false;
        reqFTP.KeepAlive = false;
        reqFTP.ContentLength = srcStream.Length;
        byte[] buff = new byte[UPLOAD_DOWNLOAD_BUFFER_SIZE];
        int contentLen;

        // Stream to which the file to be upload is written

            using (Stream dstStream = reqFTP.GetRequestStream())
            {
                // Read from the file stream 2kb at a time
                contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);

                // Till Stream content ends
                while (contentLen != 0)
                {
                    // Write Content from the file stream to the FTP Upload Stream
                    dstStream.Write(buff, 0, contentLen);
                    contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);
                }

                dstStream.Close();
            }
        }

        // Get the response to the upload request.
        bool ret;
        FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
        // ret = (response.StatusCode == FtpStatusCode.ClosingData);    // 
        response.Close();

        ret = (GetFileSize(dstFilePath) == srcStream.Length);

        return ret;
    }

当我将第 9 行更改为 reqFTP.UsePassive = true 时,服务器返回 (227 Entering Passive Mode (h1,h2,h3,h4,p1,p2))。现在它返回 (500) 语法错误,命令无法识别。会有什么问题? 谢谢

【问题讨论】:

  • 我停止了我的防病毒程序。然后文件被传输。

标签: c# networking upload ftp


【解决方案1】:

我可以在防病毒软件运行时上传图片 Filezilla。但是,当我使用我的代码块尝试它时。它返回端口错误消息。杀毒停止后,一切正常。

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 2011-01-08
    • 2017-09-13
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多