Batch FTP

G

GregNga

I have a text file, FTPSCRIPT in MYDIR, that contains a series of FTP
commands. Whenever I go to the DOS prompt and execute the command
FTP -s:C:\MYDIR\FTPSCRIPT it works perfectly and FTPs the file successfully

However, When I put it in a .bat file that contains only the command
FTP -s:C:\MYDIR\FTPSCRIPT and click on the .bat file it appears to get in a
loop, displaying the command FTP -s:C:\MYDIR\FTPSCRIPT over and over in the
DOS window and I finally have to cancel it without it ever transferring the
file.

Why does this work OK interactively on the DOS prompt but not in a .bat file
and how can I make it work in batch mode. My objective is to put an icon on
someones desktop so they can click it to run an FTP script
 
P

Pegasus [MVP]

GregNga said:
I have a text file, FTPSCRIPT in MYDIR, that contains a series of FTP
commands. Whenever I go to the DOS prompt and execute the command
FTP -s:C:\MYDIR\FTPSCRIPT it works perfectly and FTPs the file
successfully

However, When I put it in a .bat file that contains only the command
FTP -s:C:\MYDIR\FTPSCRIPT and click on the .bat file it appears to get in
a
loop, displaying the command FTP -s:C:\MYDIR\FTPSCRIPT over and over in
the
DOS window and I finally have to cancel it without it ever transferring
the
file.

Why does this work OK interactively on the DOS prompt but not in a .bat
file
and how can I make it work in batch mode. My objective is to put an icon
on
someones desktop so they can click it to run an FTP script

There is no difference (or hardly any . . .) between a batch file and the
Command Prompt. If your batch file loops then this is probably because you
have a batch file somewhere that you called ftp.bat. This is bad news - you
must never give a batch file the same name as your system files.
 
G

GregNga

You were correct, I renamed the .bat file and it worked perfectly.

Is there any way to supress the display the supression of the FTP commands
 
P

Pegasus [MVP]

GregNga said:
You were correct, I renamed the .bat file and it worked perfectly.

Is there any way to supress the display the supression of the FTP commands
on the DOS window or better yet supress/minimize the display of the DOS
window entirely when the FTP command is executed in batch

To really hide an console command you need to invoke it via the Exec command
available in VB Scripts. However, this poses a maintenance problem as you
will now have three files to look after:
a) The VB Script
b) The batch file
c) The script file
This is two files too many. To make this facility robust you should wrap the
whole lot into one single file. Here is how you can do it with a single VB
Script file:

[01] Set oFSO = CreateObject("Scripting.FileSystemObject")
[02] Set oWshShell = CreateObject("WScript.Shell")
[03] sScript = oWshShell.ExpandEnvironmentStrings("%temp%\script.scr")
[04] sLog = oWshShell.ExpandEnvironmentStrings("%temp%\script.log")
[05] sSite = "ftp.quickline.com"
[06] sAccount = "Andy"
[07] sPassword = "andrew"
[08] sFolder = "public_html/Tools"
[09] sFile = "get_.exe"
[10]
[11] Set oScript = oFSO.CreateTextFile(sScript, True)
[12] oScript.WriteLine sAccount
[13] oScript.WriteLine sPassword
[14] oScript.WriteLine "binary"
[15] oScript.writeLine "cd " & sFolder
[16] oScript.WriteLine "get " & sFile
[17] oScript.WriteLine "quit"
[18] oScript.Close
[19] Set oExec = oWshShell.Exec("ftp -s:" & sScript & " " & sSite)
[20] Do While oExec.Status = 0
[21] WScript.Sleep 100
[22] Loop
[23]
[24] Set oLog = oFSO.CreateTextFile(sLog, True)
[25] If oExec.ExitCode = 0 Then
[26] While Not oExec.StdOut.AtEndOfStream
[27] oLog.WriteLine oExec.StdOut.ReadLine
[28] Wend
[29] Else
[30] While Not oExec.StdErr.AtEndOfStream
[31] oLog.WriteLine oExec.StdErr.ReadLine
[32] Wend
[33] End If
[34] oLog.Close

Explanation:
Lines 3..9: You need to set these to suit your environment.
Lines 11-18: They create your script file. You can examine it each time
after running the script.
Lines 19-22: They execute ftp.exe.
Lines 24-30: They generate the log file. This is essential when hiding the
script - without them you'll be flying blind!

You now need to copy the code into c:\Windows\Andrew.vbs, unwrap wrapped
lines, adjust your parameters, then remove the line numbers. You can then
invoke it directly or like so: wscript c:\Windows\Andrew.vbs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top