// 参数设置
function SetFTPGen: boolean;
begin
AbortFlag := false;
result := false;
try
with MagFTPClient do
begin
LocalHost := string(OverbyteIcsWSocket.LocalHostName);
HostName1 := ftpGHost;
HostName2 := '';
SocketFamily := sfAny; // change to sfAnyIPv4 if IPV6 not allowed
UserName := ftpUser;
PassWord := ftpPsw;
FtpType := FtpTypeNone;
Port := IntToStr(ftpPort);
AttemptDelay := 5;
MaxAttempts := 2; // logon attempts
FailRepeat := 3; // retries for failed xfers
DataSocketSndBufSize := 32768; // increase speed
DataSocketRcvBufSize := 32768; // increase speed
KeepAliveSecs := 600;
// ConnectionType: ftpDirect, ftpProxy, ftpSocks4, ftpSocks4A, ftpSocks5
ConnectionType := ftpDirect;
SocksPort := '';
SocksServer := '';
ProxyPort := '';
ProxyServer := '';
SocksUsercode := '';
SocksPassword := '';
SocketErrs := wsErrFriendly;
if ConnectionType >= ftpSocks4 then
begin
SocksPort := '1080';
SocksServer := '192.168.1.66';
if ConnectionType = ftpSocks5 then
begin
SocksUsercode := '';
SocksPassword := '';
end;
end;
PassiveX := False; // must be after connection type
// HostType: FTPTYPE_NONE, FTPTYPE_UNIX, FTPTYPE_DOS, FTPTYPE_MVS, FTPTYPE_AS400, FTPTYPE_MLSD
HostType := FTPTYPE_NONE;
// TXferMode: XferModeBinary, XferModeAscii
XferMode := XferModeBinary;
// TCaseFile: FileLowerCase, FileMixedCase
CaseFile := FileMixedCase; // FileLowerCase;
DiffStampMins := 62;
Timeout := 600; // 18 Sept 2006, 60 secs was too slow for MD5Sum
DispLog := true;
DispFiles := true;
DispRDir := true;
DispLDir := false;
MinResSize := 65535; // also used for resume overlap
// MinResSize := 0 ; // test no resume overlap
ProgressEvent := Nil;
CopyEvent := Nil;
UpArchDir := '';
UpArchive := false;
ResFailed := true;
UseCompression := false;
MagFtpOpts := MagFtpOpts - [magftpNoFeat];
MagFtpOpts := MagFtpOpts - [magftpNoZlib];
MagFtpOpts := MagFtpOpts - [magftpNoTmpFile];
MagFtpOpts := MagFtpOpts - [magftpNoUtf8];
MagFtpOpts := MagFtpOpts - [magftpNoHost];
MagFtpOpts := MagFtpOpts + [magftpIgnoreUtf8];
MagFtpOpts := MagFtpOpts + [magftpNoMd5];
MagFtpOpts := MagFtpOpts - [magftpNoCrc];
ZlibNoCompExt := '.zip;.rar;.7z;.cab;.lzh;.tar;.avi;.wmv;.mpg;.mp3;.jpg;.png;';
ZlibMaxSize := 500000000; // 500 megs
MaxResumeAttempts := 10; // 重试 10 次
Options := Options - [ftpBandwidthControl]; // 带宽
{$IFNDEF NO_DEBUG_LOG}
IcsLogger := IcsLog;
// IcsLog.LogOptions := [];
{$ENDIF}
DispRemList := true;
end;
except
// AddLogText('FTP Error - ' + GetExceptMess(ExceptObject));
result := true;
end;
end;
// 上传一个文件
function UploadAFile(FTPServer, FTPPath, LocalFile: string): Boolean;
var
taskres: TTaskResult;
Replace: TFileCopyRepl;
begin
Result := False;
AbortFlag := false;
GetFTPParam(FTPServer);
MagFTPClient := TMagFtp.Create(nil);
try
if SetFTPGen then
exit;
try
with MagFTPClient do
begin
TarDir := '/';
BulkMode := BulkModeUpload;
// DelFile := FtpDelDone.Checked ; pending TMagFtp fix
Replace := FCReplNewer;
// if FtpOneReplace.Checked then
Replace := FCReplAlways;
taskres := FtpLogon;
if taskres = TaskResOKNew then
begin
taskres := FtpUpOneFile(LocalFile, FTPPath, ExtractFileName(LocalFile), Replace);
Result := True;
end;
//AddLogText('Task Result: ' + GetTaskResName(taskres));
//AddLogText(ReqResponse);
end;
except
writelog('FTP Error - ' + GetExceptMess(ExceptObject));
end;
finally
MagFTPClient.FtpLogoff;
FreeAndNil(MagFTPClient);
writelog('FTP Completed');
end;
end;
转载于:https://my.oschina.net/u/582827/blog/1545774