views:

1359

answers:

3

When I try my program on my win2k8 machine it runs fine but on win 2k3 it gives me this error that error message

here's the code that' generating the error

WebClient wc = new WebClient(); 
wc.DownloadFile("ftp://ftp.website.com/sample.zip");

there's the weird part. if i disable the firewall on the server completely. the error goes away. but it still errors if i add the program to the exception list and turn on the firewall.

have search the web for days, couldn't find any solution.

+2  A: 

You should try using passive mode for FTP. The WebClient class doesn't allow that, but FtpWebRequest does.

FtpWebRequest request = WebRequest.Create("ftp://ftp.website.com/sample.zip") 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);
    }
}
Thomas Levesque
how do i use FtpWebRequest to download a file and save it to my local drive? I examples i found only show how to display server response.
I can't post code in comments... I updated my answer
Thomas Levesque
what's nRead? i don't see that in your code. thanks
it was a mistake, I meant nBytes... it's fixed now
Thomas Levesque
A: 

Please post the complete exception, including any InnerException:

try
{
    WebClient wc = new WebClient(); 
    wc.DownloadFile("ftp://ftp.website.com/sample.zip");
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString()); // Or Debug.Trace, or whatever
    throw;    // As if the catch were not present
}
John Saunders
InnerException is empty
Post the whole thing anyway, for the stack trace.
John Saunders
A: 

I had a similar issue (no ftp) and a different solution

The production server environment had been made so secure that the server could not reach the URL.

Quick test is to use a browser on the box and see if you can navigate to the url.

Hope this helps someone.

Tim Jarvis