I am trying to write a vbscript ftp crawler. Using wscript.shell .run,
I can run ftp with some pre-generated script. If I want to go
recursively into folders, I should repeat running ftp again and again
I was wondering, if I can indeed control the ftp through wscript.shell
.exec, printing ftp commands and reading ftp responses through stdout
With some simulated CMD script (prints ftp messages, waits for inputs)
this works -- my script grabs what execed prints and submits some test
words into it.
But when I try to run the real ftp.exe, either directly, or through
comspec /c, or through some CMD script, there is always the same
When accessing stdout or stderr AtEndOfStream property, or reading from
them, cscript stops and waits forever. I mean, I can not even check for
AtEndOfStream, because this check never ends!
An example, the following script, running as cscript //nologo test1.vbs
Dim oWSH, oExec
Dim oStdout, oStdin
Dim sInput, cInput
Set oWSH = CreateObject ("WScript.Shell")
Set oExec = oWSH.Exec ("ftp.exe")
'Set oExec = oWSH.Exec ("%COMSPEC% /c %WINDIR%\System32\ftp.exe")
'Set oExec = oWSH.Exec ("test.cmd")
Set oStdout = oExec.StdOut
Set oStdin = oExec.StdIn
' Work until FTP.EXE works
Do While oExec.Status = 0
WScript.Echo "Debug . :" & "Do a check ..."
WScript.Echo "Debug 0 :" & oExec.Status
'WScript.Echo "Debug 1a:" & oStdout.Read (1)
WScript.Echo "Debug 1b:" & oStdout.AtEndOfStream
WScript.Echo "Debug 2 :" & oExec.StdErr.AtEndOfStream
WScript.Echo "Debug 3 :" & oStdin.AtEndOfStream
WScript.Echo "Debug 4 :" & "done"
' Some olgic is skipped
WScript.Echo "Debug 5 :" & "Waiting"
provides the following output:
Debug . :Do a check ...
Debug 0 :0
and waiting forever then.
Do you have any suggestions, what could be a problem with FTP.EXE when
ran through .exec ?
The same [mis]behavior is noted on Windows XP SP2, and on Windows 2000
Server with latest SP.