&& ftpSendFile lparameters Source, Destination fd = fopen(Source) if( fd < 0 ) wait window nowait 'Cannot open ' + Source return FALSE endif local fd_ftp fd_ftp = FtpOpenFile(this.ftpHandle, Destination, GENERIC_WRITE, ; FTP_TRANSFER_TYPE_BINARY + INTERNET_FLAG_RELOAD,0) if( empty(fd_ftp) ) wait window nowait 'cannot open RemoteFile ' + Destination =fclose(fd) return FALSE endif local Success, n, t, nbytes, buf Success = TRUE t = therm(fseek(fd,0,2)/1024, 'ftp ' + Source + ' >> ' + Destination ) =fseek(fd, 0, 0) n = 0 do while !feof(fd) buf = fread(fd, 8*1024) nBytes = 0 if( !empty(InternetWriteFile(fd_ftp, Buf, len(buf), @nbytes )) ) if( len(buf) == nBytes ) && ok n = n + nBytes =t.Update(n/1024) else wait window nowait 'write error, bytes <>' Success = FALSE exit endif else wait window nowait 'write error' Success = FALSE exit endif enddo =fclose(fd) =InternetCloseHandle(fd_ftp) return Success
&& ftpGetfile lparameters Source, Destination local fd_ftp fd_ftp = FtpOpenFile(this.ftpHandle, Source, GENERIC_READ,; INTERNET_FLAG_RELOAD + FTP_TRANSFER_TYPE_BINARY,0) if( empty(fd_ftp) ) wait window nowait 'cannot open remote file ' + Source return FALSE endif local fd fd = fcreate(Destination) if( fd < 0 ) wait window nowait 'cannot create ' + Destination =InternetCloseHandle(fd_ftp) return FALSE endif local FileSize, fs1, fs2, HaveFileSize fs2 = 0 fs1 = FtpGetFileSize( fd_ftp, @fs2) FileSize = fs2 * 2^32 + fs1 HaveFileSize = !(FileSize < 0 ) if( !HaveFileSize ) FileSize = 0 endif local t, n n = 0 t = therm(FileSize/1024, 'ftp ' + Destination + ' << ' + Source) local buf, BytesRead, bufSize, sts do while TRUE buf = space(64*1024) BytesRead = 0 BufSize = len(Buf) sts = InternetReadFile(fd_ftp, @Buf, BufSize, @BytesRead) if( sts = 0 ) exit else if( BytesRead = 0 ) exit else n = n + BytesRead =iif(HaveFileSize, t.Update(n/1024), t.Update(n/1024, '', n/1024) ) if( fwrite(fd, buf, BytesRead) <> BytesRead ) wait window nowait 'Write error' exit endif endif endif enddo =fclose(fd) =InternetCloseHandle(fd_ftp) if( !HaveFileSize ) FileSize = n endif return ( n == FileSize )