I have asked this question at the FPC forums (here) but answers are not forthcoming so I hoped someone here could help.
I have an Apple Mac server that has FTP enabled via SSH connection using port 22. I can connect to it fine using the FireFTP Firefox FTP plugin by specifying 'sFTP' in the encryption setting. I have another server (Windows) that I can connect to using "Implict SSL (Good)" and port 990 which I think is FTPS or similar. I can connect to that too, using FireFTP.
I have created a small demo project to see if I can connect using my own application. I have the Synpase library and the two DLL's (libssl32.dll libeay32.dll) that are needed for secure connections in my project. All compiles. But I just cannot get it to connect. The code is below. When I connect to these same FTP servers using FireFTP, I am asked if I want to accept and store the certificate. Could this be the problem? My code has no way to say "User, do you want to accept the certificate?". Is there a way to achieve this? In Delphi, such connections seem easy (http://www.example-code.com/delphi/ftp_ImplicitSSL.asp) but I am really struggling with what I had assumed would be an easy task.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ftpsend, ssl_openssl; // From Synapse library
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
function SendFTP(Host, Username, Password : string) : boolean;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
if SendFTP('My.IP.Address.123', 'FTPUserAcc', 'FTPPassword') then ShowMessage('Connected');
end;
// To just test if we can login to the server, for now. Expand once that is working
// From http://forum.lazarus.freepascal.org/index.php?topic=20061.0
function TForm1.SendFTP(Host, Username, Password : string) : boolean;
var
FTP: TFTPSend;
begin
FTP := TFTPSend.Create;
try
try
FTP.TargetHost := Host;
FTP.TargetPort := '990'; // For Implict SSL, 22 for standard SSH
FTP.AutoTLS := true; // also tried FTP.FullSSL
FTP.UserName := Username;
FTP.Password := Password;
FTP.Login;
except
on E: Exception do
begin
Showmessage('Exception: '+E.Message);
Exit;
end;
end;
FTP.Logout;
finally
FTP.Free;
end;
end;
//=============================================================================
end.