0
votes

I am using FTPWebRequest and FTPWebResponse to connect to an FTP server. This FTP server checks the number of failed logon attempts from a client, and temporarily bans a client if there are too many failed logon attempts in a specified time period. For the initial failed logon attempts, and also for any attempts after being banned, I get

"The remote server returned an error: (530) Not logged in."

If I try to connect to the FTP server manually (i.e. from a DOS prompt) after being banned, I get

c:\> ftp a.b.c.d
Connected to a.b.c.d.
530 Host w.x.y.z has been temporarily banned from the FTP server.
Connection closed by remote host.

w.x.y.z is the IP address of my local system.

Is there any way I can capture the text of the message

"530 Host w.x.y.z has been temporarily banned from the FTP server."

I need to be able to differentiate between a regular failed logon attempt ("Not Logged In") and one that was as a result of being banned, and the only way I can see to do it to capture and check the error message.

1
If I had code then I'd know how to do it...JeffR
Post your code on how you are performing the FTPWebRequest and Response!!CathalMF
It's not relevant - the code works, but it checks a status code after an exception - and in the cases documented above the same status code is returned. I need to see the message - if I knew how to do that I'd answer my own question...JeffR
Your really not helping yourself here!! If someone who is trying to help you asks you to do something, either do it or don't expect help.CathalMF
Well I'd have to do a lot of editing of the code - company confidential - to put a snippet in here, which I can do. I just don't see how my code will help anyone answer the question. I would have thought the question was fairly straightforward - how do I do that? - without the need to reference my code.JeffR

1 Answers

1
votes

Fortunately the WebException which is thrown when calling GetResponse has the FtpWebResponse inside it, and that is exactly what you want:

try
{
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
}
catch (WebException ex)
{
    if (ex.Response != null)
        Console.WriteLine(((FtpWebResponse)ex.Response).StatusDescription);
}