通过 FTP 传输 PGP 文件时出现错误:基础连接已关闭:接收时发生意外错误

发布于 2024-08-04 11:01:31 字数 832 浏览 3 评论 0原文

我正在尝试通过 FTP 上传 PGP 加密文件。但我收到如下错误消息:

底层连接已关闭:接收时发生意外错误。

我正在使用以下代码并在行中收到错误:

Stream ftpStream = response.GetResponse();

有谁可以尽快帮助我吗?

以下是代码示例:

FtpWebRequest request =
  WebRequest.Create("ftp://ftp.website.com/sample.txt.pgp") as FtpWebRequest; 
request.UsePassive = true;    
FtpWebResponse response = request.GetResponse() as FtpWebResponse;    
Stream ftpStream = response.GetResponse();    
int bufferSize = 8192;    
byte[] buffer = new byte[bufferSize];    
using (FileStream fileStream =
       new FileStream("localfile.zip", FileMode.Create, FileAccess.Write))
{
    int nBytes;
    while((nBytes = ftpStream.Read(buffer, 0, bufferSize) > 0)
    {
        fileStream.Write(buffer, 0, nBytes);
    }
}

问候, 苏米特

I am trying to upload a PGP encrypted file through FTP. But I am getting an error message as follows:

The underlying connection was closed: An unexpected error occurred on a receive.

I am using the following code and getting the error at line:

Stream ftpStream = response.GetResponse();

Is there any one who can help me out ASAP.

Following is the code sample:

FtpWebRequest request =
  WebRequest.Create("ftp://ftp.website.com/sample.txt.pgp") as FtpWebRequest; 
request.UsePassive = true;    
FtpWebResponse response = request.GetResponse() as FtpWebResponse;    
Stream ftpStream = response.GetResponse();    
int bufferSize = 8192;    
byte[] buffer = new byte[bufferSize];    
using (FileStream fileStream =
       new FileStream("localfile.zip", FileMode.Create, FileAccess.Write))
{
    int nBytes;
    while((nBytes = ftpStream.Read(buffer, 0, bufferSize) > 0)
    {
        fileStream.Write(buffer, 0, nBytes);
    }
}

Regards,
Sumeet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷爱 2024-08-11 11:01:31

您为什么尝试使用 GetResponse() 上传?
您至少需要 request.Method = WebRequestMethods.Ftp.UploadFile;request.GetRequestStream();

Why are you trying to upload using GetResponse()?
You need at least request.Method = WebRequestMethods.Ftp.UploadFile; and request.GetRequestStream();

回忆追雨的时光 2024-08-11 11:01:31
ftp.UsePassive = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.KeepAlive = false;
ftp.UseBinary = true;
ftp.UsePassive = true;
ftp.Timeout = int.MaxValue;
ftp.ReadWriteTimeout = int.MaxValue;
ftp.Proxy = null;
ftp.Credentials = new NetworkCredential(values.UserName, values.Password);
ftp.UsePassive = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.KeepAlive = false;
ftp.UseBinary = true;
ftp.UsePassive = true;
ftp.Timeout = int.MaxValue;
ftp.ReadWriteTimeout = int.MaxValue;
ftp.Proxy = null;
ftp.Credentials = new NetworkCredential(values.UserName, values.Password);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文