Link to home
Create AccountLog in
Avatar of Loganathan Natarajan
Loganathan NatarajanFlag for India

asked on

Unable to download .zip&.rar files from FTP Server

private void Download()
        {
            Uri url = new Uri("ftp://"+FtpAddress+"/filename");
            if (url.Scheme == Uri.UriSchemeFtp)
            {
                FtpWebRequest objRequest = (FtpWebRequest)FtpWebRequest.Create(url);
                //Set credentials if required else comment this Credential code
                NetworkCredential objCredential = new NetworkCredential(sFtpUsername,sFtpPassword);
                objRequest.Credentials = objCredential;
                objRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                FtpWebResponse objResponse = (FtpWebResponse)objRequest.GetResponse();
                StreamReader objReader = new StreamReader(objResponse.GetResponseStream());
                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.
Avatar of connect2kapil
connect2kapil
Flag of India image

Can you check your proxy setting, or try after bypass proxy settings...

good luck

- KD
ASKER CERTIFIED SOLUTION
Avatar of jonnidip
jonnidip
Flag of Italy image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer