views:

46

answers:

1

I have the following code to retrieve a file via FTP:

        try
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);

            request.KeepAlive = true;
            request.UsePassive = true;
            request.UseBinary = true;

            request.Method = WebRequestMethods.Ftp.DownloadFile;
            request.Credentials = new NetworkCredential(username, password);

            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            using (Stream responseStream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(responseStream))
            using (StreamWriter destination = new StreamWriter(destinationFile))
            {
                destination.Write(reader.ReadToEnd());
                destination.Flush();
            }

            return 0;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

This works in most cases, but I have one client machine where I get an exception:

The remote server returned an error 403: Forbidden

Can anyone tell me why this could be the case? It’s exactly the same code running on all clients (including the same username and password)?

A: 

The only thing I can suggest is installing Wireshark and monitoring exactly what's being transmitted between the client and server, and comparing that between different machines. If necessary, to get the messages more similar between FTP and IE, change the request's user agent. Is there any funky networking going on, like IP-based permissions?

Reinderien