By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

FtpWebRequest.GetResponse( ) is not giving exception "550 file not found"

P: 26
Hi All,

The FtpWebRequest.GetResponse( ) method is not giving "550 File not found exception " when I do a directory list operation on a invalid(not present) directory in HP Unix and Sun Solaris system, but the same is working fine in windows.

For example,
this is my uri to connect to the Sun Solaris server machine
"ftp://ssriniva:ssriniva@apfsun/apfqa/users/ssriniva/apfhome/config"

here the 'config' folder is not present in the parent directory 'apfhome'

after connecting to the server machine when I do a directory listing operations on 'config' folder , the 'GetResponse' is not giving "550 file not found" exception as expected and as a surprise it gets executed succesfully and when I execute the StreamReader function "ReadToEnd" it retiurns an empty string.

This is the same happens for HP Unix server, but this senario works fine with windows server 2003. Is this a bug in the .Net FTP classes? or Am I doing some thing wrong? Please help me to solve this problem.

Here are the logins, servers where I get the above problem

Host: rey
OS: SunOS 5.9
Username: amtest
Password: amtest_!!

Host: hal
OS: SunOS 5.10
Username: amtest
Password: amtest_!!

Host: SLC-Train01
OS: SunOS 5.8
Username: amtest
Password: amtest

Host: amind
OS: HPUX, B.11.23

Let I put my sample code here,
Expand|Select|Wrap|Line Numbers
  1.  
  2. Uri uri = new Uri("ftp://amtest:amtest_!!@rey/%2e%2e/%2e%2e/disk1/amtest/apfhome/invd.txt");
  3.  
  4. //call the ftp webrequest 
  5. FtpWebRequest ftpclientRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
  6.  
  7. //set the Ftp Webrequest Method for listing directory details
  8. ftpclientRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  9.  
  10. ftpclientRequest.Proxy = null;
  11.  
  12. try
  13. {
  14.    //calls the webresponce to read the remote ftp responce
  15.   FtpWebResponse response = (FtpWebResponse)      fpclientRequest.GetResponse();
  16.  
  17.   //Gets the Webresponce and store in the streamReader
  18.   Stream stream = response.GetResponseStream();
  19.  StreamReader sr = new StreamReader(response.GetResponseStream(),  System.Text.Encoding.ASCII);
  20.  
  21.   //Reads  the Stream 
  22.   string strResponce = sr.ReadToEnd();
  23.   response.Close();
  24. }
  25.  catch (WebException e)
  26.  {
  27.      string status = ((FtpWebResponse)e.Response).StatusDescription;
  28.   }
  29.  
Sep 7 '07 #1
Share this Question
Share on Google+
5 Replies


Plater
Expert 5K+
P: 7,872
Well it seems like "550 file not found" *SHOULD* be what is sent back. So that doesn't seem like a problem.
If all you get is an empty string then that's easy to trap for as well.

what is the actual problem you have?
Sep 7 '07 #2

P: 26
Well it seems like "550 file not found" *SHOULD* be what is sent back. So that doesn't seem like a problem.
If all you get is an empty string then that's easy to trap for as well.

what is the actual problem you have?
Why I'm not getting "550 File not found" exception when I do a directory listing operation("ListDirectoryDetails") and reading the response using "FtpWebRequest.GetResponse( )" method on a invalid directory "Config"(directory which is not present) in Hp Unix and Sun solaris server machines? , but, the same operation is giving "550 file not found" exception in Windows 2003 server.
Sep 8 '07 #3

Plater
Expert 5K+
P: 7,872
Possibly a difference in filesystems is causing it.
Just trap for it and you should be fine.
Sep 10 '07 #4

P: 26
Possibly a difference in filesystems is causing it.
Just trap for it and you should be fine.
Do you have any work arround for this?
Sep 10 '07 #5

Plater
Expert 5K+
P: 7,872
Well you can catch the exception with a try/catch block for windows PCs
Then for the other ones check the streamlength for zero
(You did say it just returns a zero-length response right?)
Sep 10 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.