FtpException not thrown on login errors

Nov 27, 2010 at 12:42 PM

I am not sure if this is a feature or not, but when login parameters (username or password) are incorrect, an exception of class System.Exception is raised with message "Unknown error (0x2eee)". Altough it's not a problem, shouldn't it be catched internally by the lib and rethrown as FtpException?

Nov 29, 2010 at 12:53 PM
Edited Nov 29, 2010 at 1:02 PM

I have the same error at "FtpFileInfo[] fi = ftp.GetFiles();"

Unknown error (0x2efd)

Coordinator
Dec 6, 2010 at 5:25 PM

The best thing to do is to change the FtpConnection.Error() method so that any error greater than ERROR_INTERNET_EXTENDED_ERROR just returns the last response information from the FTP server:

 

        private void Error()
        {
            int code = Marshal.GetLastWin32Error();

            if (code >= WININET.ERROR_INTERNET_EXTENDED_ERROR)
            {
                string errorText = InternetLastResponseInfo(ref code);
                throw new FtpException(code, errorText);
            }
            else
            {
                throw new Win32Exception(code);
            }
        }

Feb 22, 2011 at 4:03 PM

I resolved with this code.

 

using (FtpConnection ftpConnection = new FtpConnection("server", "usr", "pwd")) {
 ftpConnection.Open();
 try {
  ftpConnection.Login();
 } catch (FtpException ex) {
  MessageBox.Show(ex.Message);
 } catch (Win32Exception exW32) {
  MessageBox.Show("Error en autentificación, verifique los errores de conexion");
 }
}