Welcome to MSDN Blogs Sign in | Join | Help

adarsh's blog

Adarsh Khare works at Microsoft. Everything here, though, is his personal opinion and is not read or approved by Microsoft before it is posted. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.
WebException message vs. Response.StatusDescription on FtpWebRequest

Recently one of the reader asked an interesting question, he was using FtpWebRequest with MakeDirectory method, if directory already exist then application received the WebException with message."The remote server returned an error: (550) File unavailable (e.g., file not found, no access).". This exception message appears to be very generic and not helping the user to figure out what causes this request to fail. The reason is exception messages are generally set by framework implementation, because they also need to be localized on different language versions.

In such case if FtpWebRequest user want to diagnose and figure out why request actually failed, he could access the actual response message from server using ((FtpWebResponse)e.Response).StatusDescription property. Your actual code would look like as below

try
{
   .  .  . . . . .  .
   WebResponse response = request.GetResponse();
 . . . . . . . . . .
}
catch(WebException e)
{
        String status = ((FtpWebResponse)e.Response).StatusDescription;
}

This posting is provided "AS IS" with no warranties, and confers no rights

Posted: Wednesday, May 04, 2005 12:38 AM by adarshk

Comments

Network Class Library Team (System.Net) said:

This is a current compile of the team's existing blogs on FtpWebRequest. I am going to update it periodically

# July 25, 2008 9:24 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker