Reputation: 39
I am try to test my ftp connection,
I need to recover the time it takes to make the connection and go in a directory
and I must have an error message when the user or the password is wrong
I try this but I can't get an error when the connection is not established or the user or the password is wrong.
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
how i can make ?
Upvotes: 2
Views: 1296
Reputation: 16311
Here's one way. Add your FTP commands to a text file and pass it as an argument (using the -s
switch). Then, redirect the output of the FTP command to a file that you can parse.
' 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
Here's an example of what you might see in output.txt
when the login fails:
ftp> USER testuser
User cannot log in.
Upvotes: 1