0 votes
by (160 points)
edited

Hi, I have an issue in which I would appreciate your help. The scenario is that I am connecting to an FTP server by getting values from Database. In the same method, where i am connecting the FTP with the server, I am also calling the FTP.login(xx,xxx) method. The problem i am facing is that I can keep track of FTP State, whether it is Ready, or Disconnected etc. from the property. But I am unable to know whether the User was logged in successfully or not. I mean if the connection was successful, but for some reason, an error occurred in the Login method, how am i supposed to know whether the user is successfully logged in or not? Thanks in advance !

Applies to: Rebex FTP/SSL

4 Answers

0 votes
by (70.2k points)
edited

If the Ftp.Login method failed the FtpException is thrown. If no exception is thrown user was successfuly logged in (you don't need to check any log-in status).

0 votes
by (230 points)
edited

the problem is when failing to connect, the State is still on "Ready". so catching with FtpException not really indicates if connection succeeded or not.

for example, if you do binding to the State, Ready doesn't mean you are connected.

0 votes
by (58.9k points)
edited

In fact FtpState is now very close to being deprecated, for instance the new versions for Xamarin.iOS and Xamarin.Android will not contain it all.

It often causes confusion for users, because in fact it is related to the FTP protocol rather than actual state of the FTP connection. I.e. FtpState.Ready means that it is possible to send FTP commands but does not say anything about the usability of the FTP connection. It used to have sense in the historical releases of Rebex FTP where 1 method corresponded exactly to 1 FTP command.

Unless needed (which is really rare) we suggest - do not used the State property and use Rebex Ftp like this:

bool ready = false;
Ftp ftp = new Ftp();
try
{
    ftp.Connect("server");
    ftp.Login("user", "pass");

    // here you are connected and authenticated, so
    // either continue the work right here
    // or indicate that you are ready
    ready = true;
}
catch(FtpException ex)
{
    Console.WriteLine(ex.ToString());
}

We are working on a better way of determining if you are connected or authenticated and we will post here when it will be released.

0 votes
by (70.2k points)
edited

From Version 2013 R3 you can use Ftp.IsConnected and Ftp.IsAuthenticated properties to check the Login Status.

...