我用WIN32 INTERNET API实现ftp上传文件,提示可以连接服务器,但无法上传文件,用cuteftp等软件,或者用idftp组件在同一机器上上传都没有问题,这是怎么回事?代码如下:var 
   RemoteFile: String ; 
   LocalFile: String ; 
   sFile: String ; 
   FTPPath: String ; 
   i: integer ; 
   blnReturn: boolean ; 
   dwInternetFlags: DWORD ; 
begin 
   if (hConnect <> nil) then 
   begin 
       FTPPath := GetFTPDirectory(hConnect) ; 
       SFILE(要上传的文件名) 
       LocalFile := localDir + sFile ; 
       RemoteFile := FTPPath + sFile ; 
       StatusBar1.Panels[0].Text := 'Uploading' ; 
       blnReturn := FtpPutFile(hConnect, 
                         pchar(LocalFile), 
                         pchar(RemoteFile), 
                         dwInternetFlags, 
                         $0) ; 
      end ; 
   end ; 
end; 单步执行,到FtpPutFile这一步返回值是false,难道上传有时间限制?不能超时?哪里可以修改这个参数?

解决方案 »

  1.   


    function PutFTPFile(const PutFile, Host, UserName, Password, Dir, RemoteFile:
      PChar;
      Port: Word;): Boolean;
    var
      H, FTP: HINTERNET;
      H1: Hwnd;
    begin
      Result := False;
      H := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
      if H = nil then Exit;
      try
        FTP := InternetConnect(H, Host, Port, UserName, Password,
          INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);    if FTP = nil then Exit;
        try
          if (Dir = nil) or FtpSetCurrentDirectory(FTP, Dir) then
          begin
            Result := FtpPutFile(FTP, RemoteFile, SaveFile, False, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0);
          end;
        finally
          InternetCloseHandle(FTP);
        end;
      finally
        InternetCloseHandle(H);
      end;end;
    刚刚写的,没测试 
      

  2.   

    FtpSetCurrentDirectory改成FtpGetCurrentDirectory