Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am still very new to VBScript, and I need some help creating a log file that will show the output of an FTP. The reason that I need the log file is to later search through it for the string "Transfer complete". If I find it, then I know that the FTP worked. Below is a snip of my code. For some reason, the log file does not get written to. I also have a problem of the script continuing on before the FTP finishes. Is there a way to make the script wait until the FTP process is complete with out using the wait command?
The echoing of "found" and "not found" is only for troubleshooting purposes. If you need to see more of the code (ie.DIM), then just let me know. If you think that there is an easier way, I'm very open to making changes to the script.Thanks in advance!
Scottset objTextFile2 = fs.OpenTextFile("\\ntlifeprotest\workarea\cdpsxh\cmelog.txt",2,True)
Set wshshell = WScript.CreateObject("wscript.Shell")retcode = Wshshell.run ("cmd /c ftp -s:cmeftp.scr "&strServer&" > objTextFile2",2,True)
'wscript.echo ("retcode = "&retcode)
objTextFile2.Close
'WScript.Sleep(100000) ' 10 second delaySet objTextFile3 = fs.OpenTextFile("objTextFile2", 1)
Do Until objTextFile3.AtEndOfStream
strLine = objTextFile3.Readline
If InStr(strLine, "Transfer complete") <> 0 Then
wscript.echo strLine
wscript.echo "found"
else
wscript.echo strLine
wscript.echo "not found"
End If
Loop

Here's how I create and write to a log file:
Set objFSO = CreateObject("scripting.filesystemobject")
Set logStream = objFSO.createtextfile(logFile , True)
logStream.writeline "Text written into log file"
logStream.CloseYou probably can use an echo, but your echos are not specifying "where" to echo to, so it makes sense there is nothing in your log files.
As for pausing execution of the script until the FTP process completes, the third parameter in the Wshshell.run command should pause the script until the Run command completes if it is set to true. Yours is set to true, so I don't know why it is not working.
Michael J

I somewhat understand what you are doing Michael, but how do I make the output from the FTP write to that file?

I don't know VB but if I have a BAT, mybat, which does:
ftp -s:script
I can make a log with:
mybat > log
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |