0

I am trying this code to download a file from a Windows machine using C# against a Solaris machine and I receive error 550 - File unavailable.

        string fileName = FileName();
        string remoteUri = "xxxx";
        var webClient = new WebClient();
        webClient.Proxy = null;
        webClient.Credentials = new NetworkCredential(Settings.Default.FtpUser, Settings.Default.FtpPassword);
        webClient.BaseAddress = "ftp://"+Settings.Default.FtpHost;
        webClient.DownloadFile(remoteUri, fileName);

I have validated that the URI works when using it in the address line of an Internet Explorer.
The URI looks like this

ftp://10.99.137.99/opt/scripts/overnight/test.txt

The actual location after the login on the Unix side is

/opt/scripts/overnight/test.txt

on the Unix side.

I am able to view the file after entering my user and password. What am I doing wrong? What other steps can I take? Is there an easy way to use more manual ftp?

weismat
  • 7,195
  • 3
  • 43
  • 58
  • 1
    If you've verified the location of the file is exactly correct, then the 550 may be saying "file unavailable" when in reality the server is denying access to the file itself due to inaccurate network credentials. This may be due to the fact that you're attempting ftp through a web client instead of through an ftp client. Is there a reason you're not using FtpWebRequest? http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx – Joel Etherton Dec 03 '10 at 11:22
  • 1
    Here's another interesting article with a different answer: http://stackoverflow.com/questions/2781654/ftpwebrequest-download-file – Joel Etherton Dec 03 '10 at 11:27
  • The second fits perfectly - thanks a lot. – weismat Dec 03 '10 at 11:43
  • If you provide the link as answer, then I will accept it. – weismat Dec 03 '10 at 11:54

2 Answers2

1

Here's another interesting article with a different answer:

FtpWebRequest Download File

Community
  • 1
  • 1
Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
0
    string remoteUri = "xxxx";

Have you posted the actual code? This is the name of the remote file. It needs to be ftp://10.99.137.99/opt/scripts/overnight/test.txt not xxxx

If it isn't the actual code, can you post the code you are really using?

The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
  • Sorry for not making the dummy data consistent - but I pasted it via the debugger into Internet explorer. – weismat Dec 03 '10 at 11:41