FUNCTION ulong CopyFile(ref string lpExistingFileName,ref string lpNewFileName,ulong bFailIfExists) LIBRARY "kernel32.dll" ALIAS FOR "CopyFileA"
FUNCTION ulong MoveFile(ref string lpExistingFileName,ref string lpNewFileName) LIBRARY "kernel32.dll" ALIAS FOR "MoveFileA"
二、具体实施步骤
1、调用InternetOpen函数设置环境。
API函数:
Function Long InternetOpenA(string sAgent, long lAccessType, string sProxyName, string sProxyBypass, long lFlags) Library "wininet.dll"
Function Boolean FtpPutFileA (long hFtpSession , string lpszLocalFile, string lpszRemoteFile, long dwFlags, long dwContext ) Library "wininet.dll"
第一个参数hFtpSession是InternetConnect调用返回的句柄值。
lpszLocalFile和lpszRemoteFile分别是本地机上的文件名和将在FTP服务器上创建的文件名。
fFailIfExists 标志是 0(替换本地文件)或 1 (如果本地文件已经存在则取消)。
dwFlags 参数指定为1是用ASCII传输文件(A类传输方法),指定为2是用二进制传输文件(B类传输方法)。
最后,当使用回叫信号时,lContext 用来识别应用程序前后关系。如不使用回叫信号,值为0。
booblen bl_success
/*如果函数调用成功,为 True, 反之为False。*/
bl_success = FtpSetCurrentDirectoryA(in_lg_connection, st_directory)
IF NOT bl_success THEN RETURN -1
//文件备份
// FUNCTION ulong MoveFile(ref string lpExistingFileName,ref string lpNewFileName) LIBRARY "kernel32.dll" ALIAS FOR "MoveFileA"
IF FileExists('.\'+st_filename) THEN
st_localfile = '.\'+st_filename
st_backupfile = '.\'+st_filename + '.bak'
MoveFile(st_localfile,st_backupfile)
END IF
long INTERNET_FLAG_RELOAD = 134217728
bl_success = FtpGetFileA(in_lg_connection, st_filename, ".\" + st_filename, False, INTERNET_FLAG_RELOAD, 2, 0)
IF NOT bl_success THEN RETURN -1
4、用InternetCloseHandle 函数关闭第1、2步的句柄。
API函数:
Function Long InternetCloseHandle(long hInternetSession) Library "wininet.dll"
调用:
InternetCloseHandle(ln_lg_connection)