From a31d6f36ff09dc0ffc1418013c122fbc24ce6055 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sun, 22 Sep 2013 01:32:34 -0400 Subject: [PATCH] Directory and FidoNet FTP mailer --- mdl/m_tcp_client.pas | 2 +- mdl/m_tcp_client_ftp.pas | 43 +++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/mdl/m_tcp_client.pas b/mdl/m_tcp_client.pas index ef8ac93..df5121c 100644 --- a/mdl/m_tcp_client.pas +++ b/mdl/m_tcp_client.pas @@ -4,7 +4,7 @@ Unit m_TCP_Client; Interface -{.$DEFINE USESTRINGLIST} +{$DEFINE USESTRINGLIST} Uses {$IFDEF USESTRINGLIST} diff --git a/mdl/m_tcp_client_ftp.pas b/mdl/m_tcp_client_ftp.pas index ce4d095..aa297fb 100644 --- a/mdl/m_tcp_client_ftp.pas +++ b/mdl/m_tcp_client_ftp.pas @@ -35,7 +35,8 @@ Type Function OpenConnection (HostName: String) : Boolean; Function Authenticate (Login, Password: String) : Boolean; Function ChangeDirectory (Str: String) : Boolean; - Function SendFile (Passive: Boolean; FileName: String) : Byte; + Function GetDirectoryList (Passive, Change: Boolean; Str: String) : Boolean; + Function SendFile (Passive: Boolean; LocalFile, RemoteFile: String) : Byte; Function GetFile (Passive: Boolean; FileName: String) : Byte; Procedure CloseConnection; End; @@ -99,6 +100,7 @@ End; Procedure TFTPClient.CloseDataSession; Begin If DataSocket <> NIL Then Begin + //DataSocket.Disconnect; DataSocket.Free; DataSocket := NIL; @@ -160,7 +162,7 @@ Begin End; End; -Function TFTPClient.SendFile (Passive: Boolean; FileName: String) : Byte; +Function TFTPClient.SendFile (Passive: Boolean; LocalFile, RemoteFile: String) : Byte; Var F : File; Buffer : Array[1..8 * 1024] of Char; @@ -169,17 +171,17 @@ Var Begin Result := ftpResFailed; - If Not FileExist(FileName) Then Exit; + If Not FileExist(LocalFile) Then Exit; SetPassive(Passive); - Client.WriteLine ('STOR ' + JustFile(FileName)); + Client.WriteLine ('STOR ' + JustFile(RemoteFile)); OK := OpenDataSession; Res := GetResponse; If OK and (Res = 150) Then Begin - Assign (F, FileName); + Assign (F, LocalFile); If ioReset(F, 1, fmRWDN) Then Begin Repeat @@ -261,6 +263,37 @@ Begin Result := SendCommand('CWD ' + Str) = 250; End; +Function TFTPClient.GetDirectoryList (Passive, Change: Boolean; Str: String) : Boolean; +Begin + Result := False; + + If Change Then Begin + Result := ChangeDirectory(Str); + + If Not Result Then Exit; + End; + + SetPassive(Passive); + + Client.WriteLine ('NLST'); + + If OpenDataSession and (GetResponse = 150) Then Begin + + ResponseData.Clear; + + Repeat + If DataSocket.ReadLine(Str) <> -1 Then + ResponseData.Add(Str) + Else + Break; + Until Not DataSocket.Connected; + + Result := GetResponse = 226; + End; + + CloseDataSession; +End; + Procedure TFTPClient.CloseConnection; Begin If Client.Connected Then