我想要一个能完成上传与下载的代码,我指的上传与下载是在两个数据库之间的比如本机的数据库与服务器的数据中的数据进行比较,发现哪个新,就用新的把旧的给覆盖掉。帮忙啊………………~!!!

解决方案 »

  1.   

    从FTP上面下载文件    
      uses 
    WinInet, ComCtrls;function FtpDownloadFile(strHost, strUser, strPwd: string;Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean;function FmtFileSize(Size: Integer): string;beginif Size >= $F4240 thenResult := Format('%.2f', [Size / $F4240]) + ' Mb'elseif Size < 1000 thenResult := IntToStr(Size) + ' bytes'elseResult := Format('%.2f', [Size / 1000]) + ' Kb';end;constREAD_BUFFERSIZE = 4096; // or 256, 512, ...varhNet, hFTP, hFile: HINTERNET;buffer: array[0..READ_BUFFERSIZE - 1] of Char;bufsize, dwBytesRead, fileSize: DWORD;sRec: TWin32FindData;strStatus: string;LocalFile: file;bSuccess: Boolean;beginResult := False;{ Open an internet session }hNet := InternetOpen('Program_Name', // AgentINTERNET_OPEN_TYPE_PRECONFIG, // AccessTypenil, // ProxyNamenil, // ProxyBypass0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE{Agent contains the name of the application orentity calling the Internet functions} { See if connection handle is valid }if hNet = nil thenbeginShowMessage('Unable to get access to WinInet.Dll');Exit;end;{ Connect to the FTP Server }hFTP := InternetConnect(hNet, // Handle from InternetOpenPChar(strHost), // FTP serverport, // (INTERNET_DEFAULT_FTP_PORT),PChar(StrUser), // usernamePChar(strPwd), // passwordINTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?0, // flag: 0 or INTERNET_FLAG_PASSIVE0);// User defined number for callbackif hFTP = nil thenbeginInternetCloseHandle(hNet);ShowMessage(Format('Host "%s" is not available',[strHost]));Exit;end;{ Change directory }bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir));if not bSuccess thenbeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);ShowMessage(Format('Cannot set directory to %s.',[ftpDir]));Exit;end;{ Read size of file }if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil thenbeginfileSize := sRec.nFileSizeLow;// fileLastWritetime := sRec.lastWriteTimeend elsebeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);ShowMessage(Format('Cannot find file ',[ftpFile]));Exit;end;{ Open the file }hFile := FtpOpenFile(hFTP, // Handle to the ftp sessionPChar(ftpFile), // filenameGENERIC_READ, // dwAccessFTP_TRANSFER_TYPE_BINARY, // dwFlags0); // This is the context used for callbacks.if hFile = nil thenbeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);Exit;end;{ Create a new local file }AssignFile(LocalFile, TargetFile);{$i-}Rewrite(LocalFile, 1);{$i+}if IOResult <> 0 thenbeginInternetCloseHandle(hFile);InternetCloseHandle(hFTP);InternetCloseHandle(hNet);Exit;end;dwBytesRead := 0;bufsize := READ_BUFFERSIZE;while (bufsize > 0) dobeginApplication.ProcessMessages;if not InternetReadFile(hFile,@buffer, // address of a buffer that receives the dataREAD_BUFFERSIZE, // number of bytes to read from the filebufsize) then Break; // receives the actual number of bytes readif (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) thenBlockWrite(LocalFile, buffer, bufsize);dwBytesRead := dwBytesRead + bufsize;{ Show Progress }ProgressBar.Position := Round(dwBytesRead * 100 / fileSize);Form1.Label1.Caption := Format('%s of %s / %d %%',[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]);end;CloseFile(LocalFile);InternetCloseHandle(hFile);InternetCloseHandle(hFTP);InternetCloseHandle(hNet);Result := True;end; 
     
     
      

  2.   

    mrtxc(阿春) ,你好,非常感谢你的回帖,不过我说的 不是在internet上下载东西,我说的只是在本机与公司服务器之间的数据库进行数据的传递,这两者之间进行上传和下载数据的覆盖~!