我正在尝试测试我的 ftp 连接,
我需要恢复建立连接和进入目录所需的时间
当用户或密码错误时,我必须有一个错误信息
我尝试了这个,但是当连接未建立或者用户或密码错误时,我无法得到错误。
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.
关于testing - vbscript 测试 ftp 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30918757/