Ciao, ho queste que funzioni per gestire un collegamento ad un server FTP
function TFTPConnection.isConnected: boolean;
begin
try
FTP.Noop;
Result := FTP.LastCmdResult.Code = '200';
except
on E: Exception do
begin
Log.Error((E.ClassName + ': ' + E.Message), 'TFTPConnection.isConnected');
FTP.Disconnect;
Result := false;
end;
end;
end;
function TFTPConnection.CheckConnection: boolean;
var i, risposta: integer;
FTPs : PFTPConnectionSettings;
begin
// Se non è connesso si connette all'ftp
if not IsConnected then
//if not FTP.Connected then
for i := 0 to Count - 1 do
begin
try
FTPS := Items[i];
FTP.Host := FTPS.host;
FTP.Port := FTPS.port;
FTP.Username := FTPS.username;
FTP.password := FTPS.password;
FTP.Connect;
connectionTime := now;
ftpAfterClientLogin(Self);
TryToConnectionCount := 0;
Break;
except
on E: Exception do
begin
Log.Error((E.ClassName + ': ' + E.Message), 'TFTPConnection.CheckConnection');
inc(TryToConnectionCount);
Sleep(10000);
end;
end;
end;
Result := FTP.Connected;
end;
nei log ho questi errori:
2024-08-22 02:33:40:922 [TID 3836][ERROR ] EIdConnClosedGracefully: Connection Closed Gracefully. [TFTPConnection.isConnected]
2024-08-22 02:33:40:922 [TID 3836][ERROR ] EIdAlreadyConnected: Already connected. [TFTPConnection.CheckConnection]
2024-08-22 02:33:50:938 [TID 3836][ERROR ] EIdConnClosedGracefully: Connection Closed Gracefully. [TINewsRundown.LoadDir]
2024-08-22 02:33:50:984 [TID 3836][ERROR ] EIdConnClosedGracefully: Connection Closed Gracefully. [TFTPConnection.isConnected]
Sembra che il componente ftp pensi di essere ancora connesso e quindi non faccia la riconnessione.
Avete qualche idea o correzione al codice da suggerire?
ChatGPT suggerisce l'idea estrema di ricreare il componente. in effetti non ci avevo pensato…
Grazie in anticipo,
Andrea.