为了要用QTP完成FTP的自动下载。我从网上找到以下的代码。没有错误,但是运行却没有结果,没有下载目标文件。
单步调试时最后运行的是这句Reporter.ReportEvent micFail,"FTP:FtpGetFile function","Failed to open download file."
其它网站拷贝过来的一段代码示例,先把FTP指令保存到G:\babar\aaaa.cmd,用WshShell.Run运行:
'***************************************************************************
'****Ftp's whatever single file that has been dragged to the script icon****
'****This id for BA OUT ****************************************************
'***************************************************************************
user = "username"
pass = "pass"
ip = "ftpserverIP"
Set fs = CreateObject("Scripting.FileSystemObject") 'file withthe commands for ftp
Set objArgs = WScript.Arguments
if objArgs.Count <> 1 then
msgbox "Only Single file send. Try again."
else
strPath = wscript.ScriptFullName
name = objArgs(0)
Set a = fs.CreateTextFile("G:\babar\leifftp.com", True)
a.WriteLine (user)
a.WriteLine (pass)
'a.WriteLine ("bin")
'a.writeline ("CD 'MAILBOX.PASSAPPL.TD.TDX10CD1'")
a.WriteLine ("send " & name & " 'MAILBOX.PASSAPPL.TD.TDX10CD1'")
a.WriteLine ("quit")
a.Close
end if
Set fs = CreateObject("Scripting.FileSystemObject") 'file to run ftp with the commands above
Set a = fs.CreateTextFile("G:\babar\aaaa.cmd", True)
a.WriteLine ("ftp -i -s:G:\babar\leifftp.com " & ip)
a.Close WshShell.Run "G:\babar\aaaa.cmd",0,true