haihai1005 发表于 2010-5-11 13:17:44

QTP如何上传文件到FTP

各位:
   QTP如何将文件上传到FTP上面

TIB 发表于 2010-5-11 14:29:08

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,"www.atstudy.com",DEFAULT_FTP_PORT,"user1","user1",1,0,0)
If hConnection =0 Then Print("Failed to setup FTP environment")

' 上传
' bRetval = Extern.FtpPutFile(hConnection,sLocalFile,sRemoteFile,0)

' 下载
bRetval = Extern.FtpGetFile(hConnection,"/Mercury/QuickTest/QTP crack.rar","D:\QTP crack.rar",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)

haihai1005 发表于 2010-5-13 09:58:10

谢谢楼上的 你帮了我大忙
页: [1]
查看完整版本: QTP如何上传文件到FTP