通过 FTP 传输 PGP 文件时出现错误:基础连接已关闭:接收时发生意外错误
我正在尝试通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您为什么尝试使用
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;
andrequest.GetRequestStream();