Getting error while transfering PGP file through FTP : The underlying connection was closed: An unex
- by sumeet Sharma
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