magxfer FTP 组件 的使用例子

// 参数设置
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值