Loganathan Natarajan
asked on
Unable to download .zip&.rar files from FTP Server
private void Download()
{
Uri url = new Uri("ftp://"+FtpAddress+"/filena me");
if (url.Scheme == Uri.UriSchemeFtp)
{
FtpWebRequest objRequest = (FtpWebRequest)FtpWebReque st.Create( url);
//Set credentials if required else comment this Credential code
NetworkCredential objCredential = new NetworkCredential(sFtpUser name,sFtpP assword);
objRequest.Credentials = objCredential;
objRequest.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse objResponse = (FtpWebResponse)objRequest .GetRespon se();
StreamReader objReader = new StreamReader(objResponse.G etResponse Stream());
byte[] buffer = new byte[16 * 1024];
int len = 0;
FileStream objFS = new FileStream("Test.jpg", FileMode.Create, FileAccess.Write, FileShare.Read);
while ((len = objReader.BaseStream.Read( buffer, 0, buffer.Length)) != 0)
{
objFS.Write(buffer, 0, len);
}
objFS.Close();
objResponse.Close();
}
}
I use the above code to download files from FTP server. I am able to download the files not .zip,.rar files. How to download .zip,.rar files from FTP please help me to solve this issue. When I try to download .zip file, I get the following error The remote server returned an error: (502) Bad Gateway.
{
Uri url = new Uri("ftp://"+FtpAddress+"/filena
if (url.Scheme == Uri.UriSchemeFtp)
{
FtpWebRequest objRequest = (FtpWebRequest)FtpWebReque
//Set credentials if required else comment this Credential code
NetworkCredential objCredential = new NetworkCredential(sFtpUser
objRequest.Credentials = objCredential;
objRequest.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse objResponse = (FtpWebResponse)objRequest
StreamReader objReader = new StreamReader(objResponse.G
byte[] buffer = new byte[16 * 1024];
int len = 0;
FileStream objFS = new FileStream("Test.jpg", FileMode.Create, FileAccess.Write, FileShare.Read);
while ((len = objReader.BaseStream.Read(
{
objFS.Write(buffer, 0, len);
}
objFS.Close();
objResponse.Close();
}
}
I use the above code to download files from FTP server. I am able to download the files not .zip,.rar files. How to download .zip,.rar files from FTP please help me to solve this issue. When I try to download .zip file, I get the following error The remote server returned an error: (502) Bad Gateway.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
good luck
- KD