I saw the thread at How to check FTP connection? and tried some of the suggestions. Here's what I currently have:
private void IsFtpLoginSuccessful(FtpClient ftpClient, string ftpFolder, string ftpUsername, string ftpPassword)
{
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(ftpFolder);
requestDir.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
try
{
Log(LogLevel.Debug, "Just entered TRY block");
requestDir.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
WebResponse response = requestDir.GetResponse();
Log(LogLevel.Debug, "GOOD");
}
catch (Exception ex)
{
Log(LogLevel.Debug, "BAD");
}
}
If the username / password are invalid, the last thing that's logged is "Just entered TRY block". The code somehow silently errors-out and never logs "BAD". If the credentials are valid, it continues execution and logs "GOOD".
I suppose that gives me a Boolean as to whether the log-in was completely successful. But is there a way to distinguish whether the credentials are bad or if it's the FTP server that's just not responding?
Thank you!
You should be using the status codes in the response you get from the FTPWebRequest.
You can see a full list here
In case of your implementation
Here's the sample code on MSDN.