Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get the ftp response text in case of error.

2 views
Skip to first unread message

deostroll

unread,
Oct 24, 2008, 1:33:00 AM10/24/08
to
Suppose on a ftp session (ftp.exe) I am trying to create a directory in a
path where that directory name already exists I get the ftp response in the
console window as:

550 mydir:cannot create a file when that file already exists.

How can I retrieve the above message in my application? When I tried I got
the following error from my application:

The remote server returned an error: (550) File unavailable (e.g., file not
foun
d, no access).

The code is mentioned below for your reference:

static void CreateFTPDirectory(string dirName, string ftpURI)
{
Console.WriteLine("{0} : Creating directory {1} at {2}...",
DateTime.Now, dirName, ftpURI);
string requestURI = ftpURI + "/" + dirName;
//the ftp request object
ftpRequest = (FtpWebRequest)WebRequest.Create(requestURI);
ftpRequest.Credentials = new NetworkCredential("ituser",
"Comp68A");
ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
try
{
//the ftp response object
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
}
catch (WebException ex)
{
//WebResponse response = ex.Response;

//using (StreamReader rdr = new
StreamReader(response.GetResponseStream()))
//{
// Console.WriteLine(rdr.ReadToEnd());
// rdr.Close();
//}
Console.WriteLine(ex.Message);
return;
}
Console.WriteLine("{0} : {1}", DateTime.Now,
ftpResponse.StatusDescription);
}

I've tried reading from the response stream (look commented code) but got
nothing.

--deostroll

rajkiranpro

unread,
Nov 22, 2008, 6:27:22 AM11/22/08
to
rey using the following properties to get the messges

response.StatusCode,
response.StatusDescription

where response is the FtpWebResponse object

Regards
Rajkiran

"deostroll" <deos...@discussions.microsoft.com> wrote in message
news:677C8414-8ABC-43B0...@microsoft.com...

0 new messages