-1

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.

NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • 1
    So where did you even get the value you are trying to use? + FTP has nothing to do with SSH. + Though, if your FTP server have TLS/SSL encryption (what your code does not use in the first place), and its certificate is not signed by a trusted authority, you might need to set `TlsHostCertificateFingerprint`. – Martin Prikryl May 13 '22 at 16:02
  • The b5:d2:etc popped up I think in FileZilla setup. It's been a while since I've done the old FTP - client just wanted to have it just in case. But the question is, why am I getting a Base-64 exception on "new SessionOptions" when I'm not even passing it? – NealWalters May 13 '22 at 16:12
  • 1
    Well, then you are asking two unrelated questions. + The code you have posted cannot be throwing `FormatException`. Show us complete exception call stack. – Martin Prikryl May 13 '22 at 16:19
  • You are correct of course. Too much other stuff in the program that I'm maintaining. I will post by solution, even though it's not too likely to help others. Thanks Martin! – NealWalters May 13 '22 at 16:31

1 Answers1

-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.

NealWalters
  • 17,197
  • 42
  • 141
  • 251