Getting error while transfering PGP file through FTP : The underlying connection was closed: An unex
Posted
by sumeet Sharma
on Stack Overflow
See other posts from Stack Overflow
or by sumeet Sharma
Published on 2009-09-09T14:22:23Z
Indexed on
2010/03/14
14:05 UTC
Read the original article
Hit count: 455
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
© Stack Overflow or respective owner