C# FTP上载会超时,但不会上载文件

C# FTP上载会超时,但不会上载文件,c#,monodevelop,ftpwebrequest,C#,Monodevelop,Ftpwebrequest,我试图找出这个元素,我制作了一个ftp模块,其中包含了几个操作,除了上传方法外,所有操作都可以完美地工作。事实上,它确实可以工作,但它仍然返回一个错误 所以我在一段时间后出现超时错误,但当我检查ftp时,文件被成功添加。所以我不能理解这个特征 我的代码: public static Boolean upload(string remoteFile, string localFile, string applicatie_url) { Boolean returnbool = fa

我试图找出这个元素,我制作了一个ftp模块,其中包含了几个操作,除了上传方法外,所有操作都可以完美地工作。事实上,它确实可以工作,但它仍然返回一个错误

所以我在一段时间后出现超时错误,但当我检查ftp时,文件被成功添加。所以我不能理解这个特征

我的代码:

public static Boolean upload(string remoteFile, string localFile, string applicatie_url) {
        Boolean returnbool = false;

        try {

            FtpWebRequest ftpRequest;
            FtpWebResponse ftpResponse = null;
            Stream ftpStream = null;

            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
            ftpRequest.Credentials = new NetworkCredential(user, pass);
            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;
            ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; // upload

            byte[] b = File.ReadAllBytes(localFile);
            ftpRequest.ContentLength = b.Length;
            ftpStream = ftpRequest.GetRequestStream();

            try {

                ftpStream.Write(b, 0, b.Length);
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            } catch (Exception ex) {
                                  // Error catching
            }

            // Cleanup
            ftpStream.Close();
            ftpRequest = null;
            ftpResponse = null;
            returnbool = true;

        } catch (Exception ex) { 
          // Error catching
        }

        return returnbool;
    }
我的前男友留言:“传输超时。”

我的前任stacktrace: “”位于/Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baee2f/source/bockbuild/profiles/mono-2-10/build root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/System/System.Net/FtpWebRequest.cs:411 位于/Users/builder/data/lanes/mono-mac-ui-refresh-2-10/2baee2f/source/bockbuild/profiles/mono-2-10/build root/mono-2.10.11/_build/mono-2.10.11.git/mcs/class/System/System.Net/FtpWebRequest.cs:426中的System.Net.FtpWebRequest.GetResponse()[0x00009] 在/Users/../App_Code/FTPHelper.cs:92'中的AutoPolis.FTPHelper.upload(System.String远程文件、System.String本地文件、System.String应用程序url)[0x00078]


任何帮助都将不胜感激。我使用MonoDevelop作为IDE在我的mac上工作,不知道这是否会给这个元素带来任何机会。

我过去看过一些ftp程序,注意到在代码清理中,您编写了ftpResponse=null;但我会选择“ftpResponse.Close();”。您的stacktrace似乎提到了FTPWebRequest,因此这可能会有所帮助


p、 这可能会有所帮助:

我在过去看过一些ftp程序,并注意到在代码清理中,您编写了ftpResponse=null;但我会选择“ftpResponse.Close();”。您的stacktrace似乎提到了FTPWebRequest,因此这可能会有所帮助


p、 这可能会有帮助:

文件上传完成了吗?当我检查ftp时,我确实可以访问文件(本例中的图像)。我可以看到它没有任何问题,所以没有损坏的文件或类似的事情。尝试使用此文件是否已完成文件上载?当我检查ftp时,我确实可以访问该文件(本例中为图像)。我可以看到它没有任何问题,所以没有损坏的文件或类似的事情。尝试使用此文件时,thx并没有真正关闭响应,但确实发生了确切的错误。我注意到在我的代码中我不需要ftpresponse,所以我可以完全删除该部分。(代码确实是基于给定的url!!)嗯,thx,并没有真正关闭响应,但确实发生了确切的错误。我注意到在我的代码中我不需要ftpresponse,所以我可以完全删除该部分。(代码确实基于给定的url!!)