0 votes

I'm trying to do a simple application in C# (using WPF) that can login to my FTP server.
I am going crazy right now, because when I try to use the Login method using fixed string as parameters ("user1" and "Passowrd1.") it works fine, but when I try to pass those parameters by using strings that came from text boxes it doesn't work and I always get the following exception "User cannot log in".

Can someone help me out ?
Thank you,
Flavio P.

using (Ftp ftpClient = new Ftp())
{
    try
    {
        // details
        ftpClient.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
        ftpClient.ServerCertificateValidate += ValidateCertificate;
        ftpClient.Connect(myServerIpAddress);
        ftpClient.AuthTLS();

        // login
        // this works fine (use static strings)
        ftpClient.Login("user1", "Password1.");

        // this one no (Always throw exception)
        ftpClient.Login(ftpUsername, ftpPassword);

    }
    catch (Exception ex)
    {
        MessageBox.Show(
            ex.Message,
            "Error", 
            MessageBoxButton.OK, 
            MessageBoxImage.Error);
    }
    finally
    {
        ftpClient.Close();
    }
}

Screenshot:
- Using fixed strings:
http://fantafrog.altervista.org/onlineImages/other/ok_code.jpg
http://fantafrog.altervista.org/onlineImages/other/ok_output.jpg
- Using variables:
http://fantafrog.altervista.org/onlineImages/other/error_code.jpg
http://fantafrog.altervista.org/onlineImages/other/error_output.jpg

closed with the note: I actually resolve the problem.
by (210 points)
closed by
Can you share what the problem was?

1 Answer

+1 vote

It's really hard to tell what the problem is.

Are you sure you are entering correct username/password on the UI?
Is CapsLock off?
Are your WPF controls properly bound and strings you pass to Ftp.dll are correct?
Some additional logging might help you with that.

Are you sure you invoke Ftp.Login method just once - your code has 2 invocations - I assume this is just for illustration purposes, but it's better to check that.

Also, what is the exact error/exception you get?

You can also turn on Ftp.dll logging:
https://www.limilabs.com/blog/logging-in-ftp-dll

by (301k points)
I have edited my post, so that you can have an idea of what error I got.

Note that in both cases, username and password are the same.

Thank you.
I don't think this is related to Ftp.dll.
There must be some bug in your code, or the values you pass to Login method are different.
Please double check for unprintable characters, check if the last dot is a 'normal' dot and not some special character.
You may try convert string to hex and back to check if those are the same values.
Nothing else comes to my mind.
...