See whatsnew
This commit is contained in:
parent
8301ece4fa
commit
a537b7f5b9
|
@ -5,7 +5,7 @@ Unit m_io_Base;
|
||||||
Interface
|
Interface
|
||||||
|
|
||||||
Const
|
Const
|
||||||
TIOBufferSize = 8 * 1024 - 1;
|
TIOBufferSize = 16 * 1024 - 1;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TIOBuffer = Array[0..TIOBufferSize] of Char;
|
TIOBuffer = Array[0..TIOBufferSize] of Char;
|
||||||
|
|
|
@ -258,36 +258,6 @@ Begin
|
||||||
Result := True;
|
Result := True;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
(*
|
|
||||||
Function TIOSocket.WriteFile (Str: String) : Boolean;
|
|
||||||
Var
|
|
||||||
Buf : Array[1..4096] of Char;
|
|
||||||
Size : LongInt;
|
|
||||||
F : File;
|
|
||||||
Begin
|
|
||||||
Result := False;
|
|
||||||
|
|
||||||
FileMode := 66;
|
|
||||||
|
|
||||||
Assign (F, Str);
|
|
||||||
Reset (F, 1);
|
|
||||||
|
|
||||||
If IoResult <> 0 Then Exit;
|
|
||||||
|
|
||||||
Repeat
|
|
||||||
BlockRead (F, Buf, SizeOf(Buf), Size);
|
|
||||||
|
|
||||||
If Size = 0 Then Break;
|
|
||||||
|
|
||||||
If Buf[Size] = #26 Then Dec(Size);
|
|
||||||
|
|
||||||
WriteBuf (Buf, Size);
|
|
||||||
Until Size <> SizeOf(Buf);
|
|
||||||
|
|
||||||
Result := True;
|
|
||||||
End;
|
|
||||||
*)
|
|
||||||
|
|
||||||
Function TIOSocket.WriteBufEscaped (Var Buf: TIOBuffer; Var Len: LongInt) : LongInt;
|
Function TIOSocket.WriteBufEscaped (Var Buf: TIOBuffer; Var Len: LongInt) : LongInt;
|
||||||
Var
|
Var
|
||||||
Temp : Array[0..TIOBufferSize * 2] of Char;
|
Temp : Array[0..TIOBufferSize * 2] of Char;
|
||||||
|
@ -513,7 +483,8 @@ Begin
|
||||||
Res := 0;
|
Res := 0;
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
If FInBufPos = FInBufEnd Then Res := ReadBuf(Ch, 0);
|
If FInBufPos = FInBufEnd Then
|
||||||
|
Res := ReadBuf(Ch, 0);
|
||||||
|
|
||||||
Ch := FInBuf[FInBufPos];
|
Ch := FInBuf[FInBufPos];
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ Begin
|
||||||
// writeln('debug restype=', responsetype);
|
// writeln('debug restype=', responsetype);
|
||||||
|
|
||||||
If ResponseStr[4] = '-' Then Begin
|
If ResponseStr[4] = '-' Then Begin
|
||||||
|
// WriteLn ('DEBUG RECV EXT RES');
|
||||||
{$IFDEF USESTRINGLIST}
|
{$IFDEF USESTRINGLIST}
|
||||||
ResponseData.Clear;
|
ResponseData.Clear;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
|
@ -6,7 +6,6 @@ Interface
|
||||||
|
|
||||||
Uses
|
Uses
|
||||||
m_io_Sockets,
|
m_io_Sockets,
|
||||||
sockets,
|
|
||||||
m_Tcp_Client;
|
m_Tcp_Client;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
|
@ -33,6 +32,7 @@ Type
|
||||||
Function OpenDataSession : Boolean;
|
Function OpenDataSession : Boolean;
|
||||||
Procedure CloseDataSession;
|
Procedure CloseDataSession;
|
||||||
Function SetPassive (IsOn: Boolean) : Boolean;
|
Function SetPassive (IsOn: Boolean) : Boolean;
|
||||||
|
Function SendDataCommand (UsePassive: Boolean; Cmd: String) : LongInt;
|
||||||
Function OpenConnection (HostName: String) : Boolean;
|
Function OpenConnection (HostName: String) : Boolean;
|
||||||
Function Authenticate (Login, Password: String) : Boolean;
|
Function Authenticate (Login, Password: String) : Boolean;
|
||||||
Function ChangeDirectory (Str: String) : Boolean;
|
Function ChangeDirectory (Str: String) : Boolean;
|
||||||
|
@ -66,25 +66,28 @@ Begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
If DataSocket <> NIL Then Begin
|
If DataSocket <> NIL Then Begin
|
||||||
|
// writeln('DEBUG data socket was not NIL');
|
||||||
DataSocket.Free;
|
DataSocket.Free;
|
||||||
|
|
||||||
DataSocket := NIL;
|
DataSocket := NIL;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
If IsPassive Then Begin
|
If IsPassive Then Begin
|
||||||
DataSocket := TIOSocket.Create;
|
DataSocket := TIOSocket.Create;
|
||||||
|
|
||||||
|
// writeln ('DEBUG connecting PASV to ', dataip, ':', dataport);
|
||||||
|
|
||||||
If Not DataSocket.Connect(DataIP, DataPort) Then Begin
|
If Not DataSocket.Connect(DataIP, DataPort) Then Begin
|
||||||
DataSocket.Free;
|
DataSocket.Free;
|
||||||
DataSocket := NIL;
|
DataSocket := NIL;
|
||||||
|
|
||||||
Exit;
|
Exit;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
// writeln ('DEBUG connected PASV');
|
||||||
End Else Begin
|
End Else Begin
|
||||||
WaitSock := TIOSocket.Create;
|
WaitSock := TIOSocket.Create;
|
||||||
|
|
||||||
WaitSock.FTelnetServer := False;
|
|
||||||
WaitSock.FTelnetClient := False;
|
|
||||||
|
|
||||||
WaitSock.WaitInit(NetInterface, DataPort);
|
WaitSock.WaitInit(NetInterface, DataPort);
|
||||||
|
|
||||||
DataSocket := WaitSock.WaitConnection(10000);
|
DataSocket := WaitSock.WaitConnection(10000);
|
||||||
|
@ -171,22 +174,16 @@ End;
|
||||||
Function TFTPClient.SendFile (Passive: Boolean; LocalFile, RemoteFile: String) : Byte;
|
Function TFTPClient.SendFile (Passive: Boolean; LocalFile, RemoteFile: String) : Byte;
|
||||||
Var
|
Var
|
||||||
F : File;
|
F : File;
|
||||||
Buffer : Array[1..8 * 1024] of Char;
|
Buffer : Array[1..16 * 1024] of Char;
|
||||||
Res : LongInt;
|
Res : LongInt;
|
||||||
OK : Boolean;
|
|
||||||
Begin
|
Begin
|
||||||
Result := ftpResFailed;
|
Result := ftpResFailed;
|
||||||
|
|
||||||
If Not FileExist(LocalFile) Then Exit;
|
If Not FileExist(LocalFile) Then Exit;
|
||||||
|
|
||||||
SetPassive(Passive);
|
Res := SendDataCommand(Passive, 'STOR ' + JustFile(RemoteFile));
|
||||||
|
|
||||||
Client.WriteLine ('STOR ' + JustFile(RemoteFile));
|
If (Res = 150) Then Begin
|
||||||
|
|
||||||
OK := OpenDataSession;
|
|
||||||
Res := GetResponse;
|
|
||||||
|
|
||||||
If OK and (Res = 150) Then Begin
|
|
||||||
Assign (F, LocalFile);
|
Assign (F, LocalFile);
|
||||||
|
|
||||||
If ioReset(F, 1, fmRWDN) Then Begin
|
If ioReset(F, 1, fmRWDN) Then Begin
|
||||||
|
@ -220,21 +217,15 @@ Function TFTPClient.GetFile (Passive: Boolean; FileName: String) : Byte;
|
||||||
Var
|
Var
|
||||||
F : File;
|
F : File;
|
||||||
Res : LongInt;
|
Res : LongInt;
|
||||||
Buffer : Array[1..8 * 1024] of Char;
|
Buffer : Array[1..16 * 1024] of Char;
|
||||||
OK : Boolean;
|
|
||||||
Begin
|
Begin
|
||||||
Result := ftpResFailed;
|
Result := ftpResFailed;
|
||||||
|
|
||||||
If FileExist(FileName) Then Exit;
|
If FileExist(FileName) Then Exit;
|
||||||
|
|
||||||
SetPassive(Passive);
|
Res := SendDataCommand (Passive, 'RETR ' + JustFile(FileName));
|
||||||
|
|
||||||
Client.WriteLine('RETR ' + JustFile(FileName));
|
If (Res = 150) Then Begin
|
||||||
|
|
||||||
OK := OpenDataSession;
|
|
||||||
Res := GetResponse;
|
|
||||||
|
|
||||||
If OK And (Res = 150) Then Begin
|
|
||||||
Assign (F, FileName);
|
Assign (F, FileName);
|
||||||
|
|
||||||
If ioReWrite(F, 1, fmRWDW) Then Begin
|
If ioReWrite(F, 1, fmRWDW) Then Begin
|
||||||
|
@ -269,9 +260,27 @@ Begin
|
||||||
Result := SendCommand('CWD ' + Str) = 250;
|
Result := SendCommand('CWD ' + Str) = 250;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Function TFTPClient.SendDataCommand (UsePassive: Boolean; Cmd: String) : LongInt;
|
||||||
|
Var
|
||||||
|
OK : Boolean;
|
||||||
|
Begin
|
||||||
|
SetPassive (UsePassive);
|
||||||
|
|
||||||
|
If UsePassive Then Begin
|
||||||
|
OK := OpenDataSession;
|
||||||
|
|
||||||
|
If OK Then
|
||||||
|
Result := SendCommand(Cmd);
|
||||||
|
End Else Begin
|
||||||
|
Result := SendCommand(Cmd);
|
||||||
|
OK := OpenDataSession;
|
||||||
|
End;
|
||||||
|
|
||||||
|
If Not OK Then Result := -1;
|
||||||
|
End;
|
||||||
|
|
||||||
Function TFTPClient.GetDirectoryList (Passive, Change: Boolean; Str: String) : Boolean;
|
Function TFTPClient.GetDirectoryList (Passive, Change: Boolean; Str: String) : Boolean;
|
||||||
Var
|
Var
|
||||||
OK : Boolean;
|
|
||||||
Res : LongInt;
|
Res : LongInt;
|
||||||
Begin
|
Begin
|
||||||
If Change Then Begin
|
If Change Then Begin
|
||||||
|
@ -280,38 +289,24 @@ Begin
|
||||||
If Not Result Then Exit;
|
If Not Result Then Exit;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
SetPassive(Passive);
|
Result := False;
|
||||||
|
Res := SendDataCommand(Passive, 'NLST');
|
||||||
Client.WriteLine ('NLST');
|
|
||||||
writeln('debug NLST');
|
|
||||||
|
|
||||||
OK := OpenDataSession;
|
|
||||||
Res := GetResponse;
|
|
||||||
Result := Res = 550;
|
|
||||||
|
|
||||||
If (Res in [125, 150]) Then Begin
|
|
||||||
|
|
||||||
writeln('debug got nlst response');
|
|
||||||
|
|
||||||
|
If (Res = 125) or (Res = 150) Then Begin
|
||||||
ResponseData.Clear;
|
ResponseData.Clear;
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
If DataSocket.ReadLine(Str) <> -1 Then begin
|
If DataSocket.ReadLine(Str) <> -1 Then
|
||||||
ResponseData.Add(Str);
|
ResponseData.Add(Str)
|
||||||
writeln('debug got ', str);
|
Else
|
||||||
end Else begin
|
|
||||||
writeln('debug readline is -1');
|
|
||||||
writeln('debug ', socketerror);
|
|
||||||
Break;
|
Break;
|
||||||
end;
|
|
||||||
Until Not DataSocket.Connected;
|
Until Not DataSocket.Connected;
|
||||||
|
|
||||||
Result := GetResponse in [226, 550];
|
Res := GetResponse;
|
||||||
|
Result := Res = 226;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
CloseDataSession;
|
CloseDataSession;
|
||||||
|
|
||||||
writeln('res final ', result);
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Procedure TFTPClient.CloseConnection;
|
Procedure TFTPClient.CloseConnection;
|
||||||
|
|
Loading…
Reference in New Issue