0

In my C# project I have included ChilkatDotNet2.dll in order to connect to a SFTP server. For the moment, I have tried to implemt a simple connection method like the following:

Chilkat.Ftp2 F = null;
F = (Chilkat.Ftp2)new Chilkat.Ftp2();
F.Hostname = "sftp.domain.com";
F.Username = "username";
F.Password = "password";
F.Port = 22;
F.AuthTls = true;

if (!(F.Connect())) {
    MainFrm.set_AlertMessage(F.ConnectFailReason); 
}

and it always fails connecting and I always get the error 200 which means

Connected, but failed to receive greeting from FTP server.

according to Chilkat documentation.

What am I missing? I have tried to connect to a simple ftp server test (without SSL/TLS) and it connects correctly so I think I am missing something. The credentials I was given are correct as I tried to connect to the SFTP server with Filezilla. Thank you.

UPDATE

Chilkat.SFtp v_SFTP = null;
v_SFTP = (Chilkat.SFtp)new Chilkat.SFtp();
if (v_SFTP.Connect("sftp.domain.com", 22) {
    if (v_SFTP.AuthenticatePw("username", "password")) {
      IDVariant v_SUCCESS = null;
      bool v_SUCCESS = v_SFTP.InitializeSftp();
    }
}
else {
    MainFrm.set_AlertMessage(v_SFTP.LastErrorText); 
}
SagittariusA
  • 5,289
  • 15
  • 73
  • 127
  • 200 is DONE and indicates you got a good connection. So the server did not send a greeting. Maybe the server did not send a greeting. When you logon with Filezilla did you get a greeting? – jdweng Sep 21 '17 at 12:09
  • I would use a sniffer like wireshark or fiddler and capture connection for both ChilkatDotNet2 and Filezilla. I think you are missing an http header, but not sure. – jdweng Sep 21 '17 at 12:17
  • @jdweng: thank you for your kind reply. I'm trying to do what you suggested to me but it seems that fiddler cannot capture anything concerning FTO, either from my web application running the .NET code or from FileZilla. Anyway, I (have to) use Cassini to test locally the web application before deploy it. Could this be the problem? – SagittariusA Sep 21 '17 at 12:33
  • FTP uses TCP as transport layer. WebBrowsers have the capability of using FTP. You are using the secure version SFTP (port 22) which uses SCTP (Stream Control Transmission Protocol). Since you are getting 200 none of this really makes a difference. Usually when you login to an FTP site a Welcome message usually gets displayed. You are not getting the welcome message. It is possible that the server isn't sending a welcome message. You should at least get a prompt back. Sometime you have to send return to get welcome message. I suspect the wrong return is being sent (cr vs crlf). – jdweng Sep 21 '17 at 14:43

1 Answers1

1
F = (Chilkat.Ftp2)new Chilkat.Ftp2();

Chilkat.Ftp2 is an FTP client. It supports the FTP protocol. SFTP is a completely different protocol which just happens to have a similar name.

If you want to connect to an SFTP server using Chilkat, look at Chilkat.SFtp.

Kenster
  • 23,465
  • 21
  • 80
  • 106
  • Thank you, very kind of yours. Now I understand better but I am afraid things are worse than expcted. I wrote the code as you suggested (if you want have a look at my updated answer) but I got this error message: "Product is not unlocked. Make sure to call UnlockComponent first". So it turns out Chilkat is not free. I don't know why it did not notify this when I tried with simple FTP. Isn't there a developer test license? Like SQL Server 2016 Dev. If I see it works well I will try to convince my bosses to buy a license... – SagittariusA Sep 21 '17 at 13:24
  • I'm not a C# developer, and requests to recommend a library aren't on topic here. That said, there are other C# SSH/SFTP clients besides Chilkat. – Kenster Sep 21 '17 at 13:37