为什么执行 GetRequestStream 使方法 returns?

why is executing GetRequestStream making the method returns?

我正在尝试将文件上传到 ftp 服务器,使用 Ftp zilla 似乎可以正常工作,而且我可以从 Opera 登录。这是我为此编写的代码,基本上是从互联网上窃取的。在执行此方法时,当到达 GetRequestStream 并等待服务器完成其工作时,我可以在 visual studio 调试器中清楚地看到该方法从未到达 GetRequestStream 之后的行。

        FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(_url);
        ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);

        ftp.KeepAlive = true;
        ftp.UseBinary = true;
        ftp.Method = WebRequestMethods.Ftp.UploadFile;

        FileStream fs = File.OpenRead(_filefullname);
        byte[] buffer = new byte[fs.Length];
        fs.Read(buffer, 0, buffer.Length);
        fs.Close();

        Stream ftpstream = ftp.GetRequestStream();
        ftpstream.Write(buffer, 0, buffer.Length);
        ftpstream.Close();

这确实是一个例外,正如罗恩和巴迪提到的那样我没有注意到