Testing vbscript测试ftp连接
我正在尝试测试我的ftp连接 我需要恢复建立连接并进入目录所需的时间 我必须有一个错误消息时,用户或密码是错误的 我尝试了这一点,但当连接未建立或用户或密码错误时,我不会出现错误Testing vbscript测试ftp连接,testing,vbscript,ftp,connection,Testing,Vbscript,Ftp,Connection,我正在尝试测试我的ftp连接 我需要恢复建立连接并进入目录所需的时间 我必须有一个错误消息时,用户或密码是错误的 我尝试了这一点,但当连接未建立或用户或密码错误时,我不会出现错误 Set WshShell = CreateObject("WScript.Shell" ) wshShell.run "ftp.exe",true wscript.sleep 100 date_before_timestamp=Timer
Set WshShell = CreateObject("WScript.Shell" )
wshShell.run "ftp.exe",true
wscript.sleep 100
date_before_timestamp=Timer
WshShell.SendKeys "ftp.exe"&chr(13)
WshShell.SendKeys "open 127.0.0.1 21"&chr(13)
WshShell.SendKeys "galene"&chr(13)
WshShell.SendKeys "galene"&chr(13)
WshShell.SendKeys "cd test"&chr(13)
WshShell.SendKeys "quit"&chr(13)
WshShell.SendKeys chr(13)
date_after_timestamp=Timer
interval= date_after_timestamp - date_before_timestamp
wscript.echo interval
我该怎么做 这里有一个方法。将FTP命令添加到文本文件并将其作为参数传递(使用
-s
开关)。然后,将FTP命令的输出重定向到可以解析的文件
' Create the FTP command file...
With CreateObject("Scripting.FileSystemObject").CreateTextFile("c:\ftp.txt", True)
.WriteLine "USER testuser" ' Login
.WriteLine "secret1" ' Password
.WriteLine "cd test" ' Perform a command once logged in
.WriteLine "quit" ' Done
.Close
End With
' Run the command and capture its output...
With CreateObject("WScript.Shell")
tmrStart = Timer
.Run "%comspec% /c ftp -n -v -s:c:\ftp.txt ftp.mysite.com >c:\output.txt", 0, True
tmrEnd = Timer
End With
以下是登录失败时您可能在output.txt
中看到的示例:
ftp> USER testuser
User cannot log in.