'WinSCP .net library - Protocol.Ftp - System.FormatException Invalid length for a Base-64 char array or string

I have SFTP working, just to trying to add Ftp to our existing program. Is SshHostKeyFingerprint recommended for Ftp protocol the same as with SFtp?

If needed, how would I format this key? Does it need a prefix like "sha-256-"?

b5:d2:ab:1a:07:9c:88:b7:0a:fc:6e:1a:f1:c0:aa:c5:c4:93:c3:32:ce:bc:a1:e3:f1:4a:2c:02:f8:32:35:c9

I'm getting an error when running this C# code:

                sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Ftp,
                    HostName = HostName,
                    PortNumber = HostPort,
                    UserName = UserName,
                    Password = Password
                };

Resulting error of running this is:

Exception thrown: 'System.FormatException' in mscorlib.dll Invalid length for a Base-64 char array or string.



Solution 1:[1]

The program did not have a full stack trace in the error. When I added that, I see the module that contains the error: "WinSCPWrapperGet.Program.get_Password()" (where "WinSCPWrapperGet" is the program I'm modifying).

I made a poor assumption that since I had a before and after log statement, that the error was in the WinScp library.

            WriteLogConsole("Using Protocol.Ftp");
            sessionOptions = new SessionOptions
            {
                Protocol = Protocol.Ftp,
                HostName = HostName,
                PortNumber = HostPort,
                UserName = UserName,
                Password = Password
            };
            WriteLogConsole("Used Protocol.Ftp");

It turns out that "Password" is a property that has some "getter logic"...

static string Password { get { return Encoding.ASCII.GetString(Convert.FromBase64String(GetStringValueFromConfigKey("Password", ""))); } }

We base64 encode our passwords in our config file, and I failed to do that. So I will probably change that code to a give more friendly error as well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1