I’m trying to read a txt file from a ftp server and I’m getting a “550 File not found.” error even I’m %100 sure that the file is there.
Here are the variations for URI I’ve tried:
ftp://server/MySubFolder/MyFile.txt
ftp://server/%2fMySubFolder/MyFile.txt
ftp://server/MySubFolder/%2fMyFile.txt
ftp://server/%2fMySubFolder/%2fMyFile.txt
ftp://server/%2f/MySubFolder/MyFile.tx
ftp://server/MySubFolder/%2f/MyFile.txt
ftp://server/%2f/MySubFolder/%2f/MyFile.txt
They all return the same result page:
200 Type set to I.
200 PORT command successful.
550 The system cannot find the path specified.
Here’s the code I’m trying:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(file);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string content = reader.ReadToEnd();
reader.Close();
response.Close();
I also tried calling SetMethodRequiresCWD before creating my FtpWebRequest objects but it didn’t help either.
My application is a .NET 4.0 Client Profile Windows Service.
I’d appreciate any help.
Solved this problem like this: The server the service is running on is a Hyper-X virtual machine. Somehow the VM acts like a proxy. I added
request.Proxy = null;to my requests and both upload and download works now.