testing - vbscript 测试 ftp 连接

标签 testing vbscript ftp connection

我正在尝试测试我的 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/

相关文章:

python - 是否有标准方法告诉 py.test 针对特定代码运行?

testing - 黑莓网络测试

java - Jmeter - 加权随机值?

javascript - Protractor 测试: Is it able to block/freeze the DOM during test execution?

VBscript 用于确认文件列表存在且已在当天修改

vbscript - 如果进程已经在运行,我如何获取它?

c# - 如何在 FtpWebRequest 之前检查 FTP 上是否存在文件

asp-classic - 如何在经典asp中使用vbscript下载文件

java - java FTP上传问题

vb.net - 使用 FtpWebRequest 将文件从 azure 托管应用程序上传到外部 ftp 站点