ftp.pas
来自「Monster FTP Client 强大的ftp客户控件,支持Proxy等」· PAS 代码 · 共 2,250 行 · 第 1/5 页
PAS
2,250 行
end;
33: {following a STOR}
begin
if line[1] = '1' then Exit;
if line[1] = '2' then
begin
ReadyMain := True;
if ReadyPort then Ready;
end
else
begin
DataSocket.Disconnect; {close data connection}
ListeningSocket.Disconnect;
if (Aborted) and (Copy(Line, 1, 3) = '426') then
begin
if Assigned(FAborted) then FAborted(Self);
CallNEvents(13);
end
else
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
end;
Ready;
end;
end;
40: {following a RNFR}
begin
if line[1] = '3' then
Proceed('RNTO ' + rnto, 41)
else
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
Step := 100;
Ready;
end;
end;
41: {following a RNTO}
begin
if line[1] <> '2' then
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
end;
Step := 100;
Ready;
end;
50: {following a MKD, DELE or a custom command}
begin
if line[1] <> '2' then
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
end;
Step := 100;
Ready;
end;
51: {following a CD or CDUP command}
begin
if line[1] <> '2' then
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
Ready;
end
else
begin
{setting new CurrentDirectory property}
i := Pos('"', line);
if i > 0 then
begin
FDirectory := Copy(line, i + 1, 999);
FDirectory := Copy(FDirectory, 1, Pos('"', FDirectory) - 1);
Step := 100;
Ready;
end
else
Proceed('PWD', 52);
end;
end;
52: {following a PWD command}
begin
if line[1] <> '2' then
begin
DoFtpInfo(ftpPermissionDenied, '');
FSuccess := False;
end
else
begin
{setting new CurrentDirectory property}
FDirectory := Copy(line, Pos('"', line) + 1, 999);
FDirectory := Copy(FDirectory, 1, Pos('"', FDirectory) - 1);
if (FType = ftpstNetTerm) or (FType = ftpstServU) then
FDirectory := DOSName2UnixName(FDirectory);
end;
Step := 100;
Ready;
end;
60: {following a QUIT}
begin
ControlLoggedIn := False;
if line[1] <> '2' then FatalError(ftpNone);
Step := 100;
end;
90: {unset busy flag after we recivied the reply of NOOP command}
begin
if (line[1] = '5') and (line[2] = '0') then Supports[1] := False;
FBusy := False;
end;
110: {test if the site supports REST command}
begin
if line[1] = '3' then
begin
FSupportResume := True;
DoFtpInfo(ftpSupportResume, 'This site can resume broken downloads/uploads');
end
else
begin
FSupportResume := False;
DoFtpInfo(ftpNotSupportResume, '');
end;
Proceed('REST 0', 111);
end;
111: {set initial directory}
begin
if URLMode > 0 then
begin
Step := 200;
FTPProc('299');
Exit;
end;
if FIDirectory = '' then
Proceed('PWD', 6)
else
Proceed('CWD ' + FIDirectory, 112);
end;
112: {igrone error in setting initial directory}
begin
if line[1] = '2' then
begin
FDirectory := Copy(line, Pos('"', line) + 1, 999);
FDirectory := Copy(FDirectory, 1, Pos('"', FDirectory) - 1);
DoFtpInfo(ftpLoggedIn, '');
Step := 100;
Ready;
end
else
Proceed('PWD', 6);
end;
120: {size checking}
begin
if line[1] <> '2' then
begin
if (line[1] = '5') and (line[2] = '0') then
begin
Supports[2] := False;
line := '213 '+ IntToStr(FileSize(datafile));
end
else
begin
Step := 21;
FTPProc('299');
exit;
end;
end
else
begin
DownloadSize := StrToInt(Copy(line, 5, 999));
if (DownloadSize < FileSize(datafile)) or (FileSize(datafile) = 0) then
begin
DoFtpInfo(ftpNotSupportResume, 'I don'#39't know how to resume this file, I will overwrite it.');
Step := 21;
FTPProc('299');
end
else
begin
if DownloadSize = FileSize(datafile) then
begin
DoFtpInfo(ftpNothing, 'I am afraid I have nothing to do.');
FileOpened := False;
CloseFile(datafile);
FTPLastAction := ftplaNone;
Ready;
end
else
begin
seek(datafile, FileSize(datafile));
Step := 121;
FTPProc('299');
end;
end;
end;
end;
121: {REGET: same as 21}
begin
if line[1] = '2' then
if FPassive then
begin
pStep := 122;
Proceed('PASV', 13)
end
else
Proceed('PORT ' + SetupDataPort, 122)
else
FatalError(ftpProtocolError);
end;
122: {REGET: same as 22}
begin
if line[1] <> '2' then
FatalError(ftpProtocolError)
else
begin
with DataSocket do
begin
OnReadReady := DataRetrFile;
OnDisconnected := DataFileDisconnected;
OnWriteReady := nil;
if FPassive then
OnConnected := DataListConnected
else
ListeningSocket.OnAccept := DataListConnected;
end;
Proceed('REST ' + IntToStr(FileSize(datafile)), 123);
end;
end;
123: {following a REST}
begin
if line[1] = '3' then
Proceed('RETR ' + FSelection, 23)
else
begin
DataSocket.Disconnect;
ListeningSocket.Disconnect;
DoFtpInfo(ftpResumeFailed, 'Failed in resuming downloading file');
FSuccess := False;
Ready;
end;
end;
130: {get size of file which will be uploaded if it existed on server}
begin
if line[1] <> '2' then
begin
if (line[1] = '5') and (line[2] = '0') then Supports[2] := False;
Step := 31;
FTPProc('299');
end
else
begin
UploadSize := StrToInt(Copy(line, 5, 999));
if UploadSize = 0 then
begin
Step := 31;
FTPProc('299');
end
else
begin
if (Assigned(NeedInfo)) then NeedInfo(self, niOverwrite, s);
if s = 'Resume' then
begin
Seek(datafile, UploadSize);
Step := 131;
FTPProc('299');
end
else
begin
if (s = 'Overwrite') or (s = '') then
begin
Step := 31;
FTPProc('299');
end
else
begin
FileOpened := False;
CloseFile(datafile);
FTPLastAction := ftplaNone;
Ready;
end;
end;
end;
end;
end;
131: {REPUT: same as 31}
begin
ReadyPort := False;
ReadyMain := False;
if line[1] = '2' then
if FPassive then
begin
pStep := 132;
Proceed('PASV', 13)
end
else
Proceed('PORT ' + SetupDataPort, 132)
else
FatalError(ftpProtocolError);
end;
132: {REPUT: same as 32}
begin
if line[1] <> '2' then
begin
FatalError(ftpProtocolError);
FSuccess := False;
end
else
begin
with DataSocket do
begin
OnReadReady := nil;
OnDisconnected := DataFileDisconnected;
if FPassive then
begin
OnWriteReady := DataStorConnected;
OnConnected := DataListConnected;
end
else
begin
OnWriteReady := nil;
ListeningSocket.OnAccept := DataStorConnected;
end;
end;
Proceed('REST ' + IntToStr(UploadSize), 133);
end;
end;
133: {following a REST}
begin
if line[1] = '3' then
Proceed('STOR ' + FSelection, 33)
else
begin
DataSocket.Disconnect;
ListeningSocket.Disconnect;
DoFtpInfo(ftpResumeFailed, 'Failed in resuming uploading file');
FSuccess := False;
Ready;
end;
end;
200: {URL: reset current directory if the specified url is a directory}
begin
UrlMode := 0;
if FUrl = '' then
Proceed('PWD', 201)
else
Proceed('CWD ' + FUrl, 201);
end;
201:
begin
if line[1] = '2' then
begin
FtpLastAction := ftplaCWD;
FDirectory := Copy(line, Pos('"', line) + 1, 999);
FDirectory := Copy(FDirectory, 1, Pos('"', FDirectory) - 1);
if not ControlLoggedIn then
begin
ControlLoggedIn := True;
DoFtpInfo(ftpLoggedIn, '');
end;
Step := 51;
FTPLogin(line);
end
else
begin
i := Length(FUrl);
for j := i downto 1 do
begin
if FUrl[j] = '/' then
begin
FSelection := Copy(FUrl, j + 1, 999);
Delete(FUrl, j + 1, 999);
Break;
end;
end;
Proceed('CWD ' + FUrl, 202);
end;
end;
202:
begin
if line[1] = '2' then
begin
if not ControlLoggedIn then
begin
ControlLoggedIn := True;
DoFtpInfo(ftpLoggedIn, '');
end;
if FSelection <> '' then
begin
if (Assigned(NeedInfo)) and (FFile = '') then
begin
FFile := '';
NeedInfo(Self, niLocalFile, FFile);
if FFile = '' then
begin
// FtpLastAction := ftplaCWD;
Disconnect;
Exit;
end;
end;
FBusy := False;
GetFile(FSelection, FFile);
end;
end
else
begin
FRemain := -1;
FatalError(ftpFileNotFound);
end;
end;
300:
begin
if line[1] <> '2' then FSuccess := False;
if FDList.Count > 0 then
begin
S := FDList[0];
FDList.Delete(0);
Proceed('MKD ' + S, 300);
end
else
begin
if not FSuccess then DoFtpInfo(ftpPermissionDenied, '');
Step := 100;
Ready;
end;
end;
301:
begin
if line[1] <> '2' then FSuccess := False;
if FFList.Count > 0 then
begin
S := FFList[0];
FFList.Delete(0);
Proceed('DELE ' + S, 301);
end
else
begin
if not FSuccess then DoFtpInfo(ftpPermissionDenied, '');
Step := 100;
Ready;
end;
end;
310:
begin
if line[1] <> '2' then
begin
if Supports[3] then
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?