|
本帖最后由 cswalkman 于 2010-10-19 16:16 编辑
为了要用QTP完成FTP的自动下载。我从网上找到以下的代码。没有错误,但是运行却没有结果,没有下载目标文件。
单步调试时最后运行的是这句Reporter.ReportEvent micFail,"FTP:FtpGetFile function","Failed to open download file."
然后在网上找资料仔细了解其中各个函数参数的定义。但是却没有任何解决思路。
其中hConnection我用msgbox能获得一个长整数,msgbox bRetval得到是零。
请教各位高手帮帮我,指出是哪里有错误需要修改。感激不尽!!!
Const DEFAULT_FTP_PORT =21
Const SERVICE_FTP = 1
Const OPEN_TYPE_DIRECT = 1
Const FTP_TRANSFER_TYPE_ASCII = 1
Extern.Declare micLong,"InternetOpen","wininet.dll","InternetOpenA",micString,micDWord,micString,micString,micDWord
Extern.Declare micLong,"InternetConnect","wininet.dll","InternetConnectA",micLong,micString,micInteger,micString,micString,micDWord,micDWord,micDWord
Extern.Declare micInteger,"FtpGetFile","wininet.dll","FtpGetFileA",micLong,micString,micString,micInteger,micDWord,micDWord,micDWord
Extern.Declare micInteger,"FtpPutFile","wininet.dll","FtpPutFileA",micLong,micString,micString,micDWord
Extern.Declare micInteger,"InternetCloseHandle","wininet.dll","InternetCloseHandle",micLong
' --------------------打开
hInternet = Extern.InternetOpen("QTP_FTP",OPEN_TYPE_DIRECT ,vbNullChar,vbNullChar,0)
If hInternet=0 Then Print("QTP_FTP:Failed to setup FTP environment.")
' ------------------连接
hConnection = Extern.InternetConnect(hInternet,"10.243.233.2",DEFAULT_FTP_PORT,"yonghuming","mima",1,0,0)
If hConnection =0 Then Print("Failed to setup FTP environment")
' -------------------上传
' bRetval = Extern.FtpPutFile(hConnection,sLocalFile,sRemoteFile,0)
' ----------------下载
bRetval = Extern.FtpGetFile(hConnection,"/home/qytanbingjian/tan.ctl","D:\Personal\Desktop\tan.ctl",0,0,1,0)
If Not CBool(bRetVal) Then
Reporter.ReportEvent micFail,"FTP:FtpGetFile function","Failed to open download file."
else
Print("FTP:File QTP crack.rar downloaded successfully")
'Reporter.ReportEvent micPass,"FTP:FtpPutFile function","FTP:File"&sLocalFile&"upload successfully."
End If
' --------------关闭
Extern.InternetCloseHandle(hConnection)
Extern.InternetCloseHandle(hInternet) |
|