Should not crash when data port cannot be received during file transfer
This commit is contained in:
parent
c12aa847be
commit
ada1c5dfd1
|
@ -34,13 +34,16 @@ Uses
|
||||||
m_FileIO,
|
m_FileIO,
|
||||||
m_Strings;
|
m_Strings;
|
||||||
|
|
||||||
|
Const
|
||||||
|
ftpDefaultDataPort = 20;
|
||||||
|
|
||||||
Constructor TFTPClient.Create (NetI: String);
|
Constructor TFTPClient.Create (NetI: String);
|
||||||
Begin
|
Begin
|
||||||
Inherited Create(NetI);
|
Inherited Create(NetI);
|
||||||
|
|
||||||
IsPassive := False;
|
IsPassive := False;
|
||||||
DataIP := '';
|
DataIP := '';
|
||||||
DataPort := 10000;
|
DataPort := ftpDefaultDataPort;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function TFTPClient.OpenDataSession : Boolean;
|
Function TFTPClient.OpenDataSession : Boolean;
|
||||||
|
@ -151,7 +154,7 @@ Begin
|
||||||
End;
|
End;
|
||||||
End Else Begin
|
End Else Begin
|
||||||
IsPassive := False;
|
IsPassive := False;
|
||||||
DataPort := 10000; // Calc and make configurable?
|
DataPort := ftpDefaultDataPort;
|
||||||
Result := SendCommand('PORT ' + strReplace(Client.PeerIP, '.', ',') + ',' + strI2S(WordRec(DataPort).Hi) + ',' + strI2S(WordRec(DataPort).Lo)) = 200;
|
Result := SendCommand('PORT ' + strReplace(Client.PeerIP, '.', ',') + ',' + strI2S(WordRec(DataPort).Hi) + ',' + strI2S(WordRec(DataPort).Lo)) = 200;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
@ -161,6 +164,7 @@ Var
|
||||||
F : File;
|
F : File;
|
||||||
Buffer : Array[1..8 * 1024] of Char;
|
Buffer : Array[1..8 * 1024] of Char;
|
||||||
Res : LongInt;
|
Res : LongInt;
|
||||||
|
OK : Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
|
@ -174,9 +178,9 @@ Begin
|
||||||
|
|
||||||
Client.WriteLine ('STOR ' + JustFile(FileName));
|
Client.WriteLine ('STOR ' + JustFile(FileName));
|
||||||
|
|
||||||
OpenDataSession;
|
OK := OpenDataSession;
|
||||||
|
|
||||||
If GetResponse = 150 Then Begin
|
If OK and (GetResponse = 150) Then Begin
|
||||||
WriteLn ('DEBUG BEGIN SEND FILE');
|
WriteLn ('DEBUG BEGIN SEND FILE');
|
||||||
|
|
||||||
Assign (F, FileName);
|
Assign (F, FileName);
|
||||||
|
@ -197,15 +201,22 @@ Begin
|
||||||
CloseDataSession;
|
CloseDataSession;
|
||||||
|
|
||||||
Result := GetResponse = 226;
|
Result := GetResponse = 226;
|
||||||
End Else
|
End Else Begin
|
||||||
|
If IsPassive Then
|
||||||
|
WriteLn ('DEBUG unable to connect to FTP server for data session')
|
||||||
|
Else
|
||||||
|
WriteLn ('DEBUG unable to establish data session on port ', DataPort);
|
||||||
|
|
||||||
CloseDataSession;
|
CloseDataSession;
|
||||||
End;
|
End;
|
||||||
|
End;
|
||||||
|
|
||||||
Function TFTPClient.GetFile (Passive: Boolean; FileName: String) : Boolean;
|
Function TFTPClient.GetFile (Passive: Boolean; FileName: String) : Boolean;
|
||||||
Var
|
Var
|
||||||
F : File;
|
F : File;
|
||||||
Res : LongInt;
|
Res : LongInt;
|
||||||
Buffer : Array[1..8*1024] of Char;
|
Buffer : Array[1..8*1024] of Char;
|
||||||
|
OK : Boolean;
|
||||||
Begin
|
Begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
|
@ -215,9 +226,9 @@ Begin
|
||||||
|
|
||||||
Client.WriteLine('RETR ' + JustFile(FileName));
|
Client.WriteLine('RETR ' + JustFile(FileName));
|
||||||
|
|
||||||
OpenDataSession;
|
OK := OpenDataSession;
|
||||||
|
|
||||||
If GetResponse = 150 Then Begin
|
If OK And (GetResponse = 150) Then Begin
|
||||||
Assign (F, FileName);
|
Assign (F, FileName);
|
||||||
|
|
||||||
If ioReWrite(F, 1, fmRWDW) Then Begin
|
If ioReWrite(F, 1, fmRWDW) Then Begin
|
||||||
|
@ -236,9 +247,12 @@ Begin
|
||||||
CloseDataSession;
|
CloseDataSession;
|
||||||
|
|
||||||
Result := GetResponse = 226;
|
Result := GetResponse = 226;
|
||||||
End Else
|
End Else Begin
|
||||||
|
WriteLn ('DEBUG unable to open data session, receive aborted');
|
||||||
|
|
||||||
CloseDataSession;
|
CloseDataSession;
|
||||||
End;
|
End;
|
||||||
|
End;
|
||||||
|
|
||||||
Function TFTPClient.ChangeDirectory (Str: String) : Boolean;
|
Function TFTPClient.ChangeDirectory (Str: String) : Boolean;
|
||||||
Begin
|
Begin
|
||||||
|
|
Loading…
Reference in New Issue