Emulated DOS FTP script ?



Steve
07-09-2005, 11:35 PM
Trying to make a batch file that will handle some FTP tasks for me.
I have a batch file that creates a FTP script file.

Here is the batch file:
<code>
@echo off
:: Execute the ping and store results in tmp file
SET RESULTS=C:\updextipres_neverstill.txt
ping -r 1 -n 1 www.yahoo.com > %RESULTS%


:: Create FTP script for this site
SET FTPSCRIPT="C:\FTPScript.txt"

ECHO open ftp19.******.com > %FTPSCRIPT%
ECHO ******* >> %FTPSCRIPT%
ECHO ****** >> %FTPSCRIPT%
ECHO cd webroot >> %FTPSCRIPT%
ECHO cd temp >> %FTPSCRIPT%
ECHO ascii >> %FTPSCRIPT%
ECHO send %RESULTS% >> %FTPSCRIPT%
ECHO bye >> %FTPSCRIPT%

:: Execute ftp using script
%windir%\system32\ftp.exe -n -s:%FTPSCRIPT%

:: Cleanup tmp files
del %FTPSCRIPT%
del %RESULTS%
@echo off
</code>

This create the script file that looks like this:
<code>
open ftp19.******.com
username
password
cd webroot
cd temp
ascii
send C:\updextipres_neverstill.txt
bye
</code>


When I run the batch file, this is what I get:
<console output>
C:\>update_external_ip.bat
ftp> open ftp19.********.com
Connected to ftp19.brinkster.com.
220 Microsoft FTP Service
ftp> brinkusername Invalid command.
ftp> password Invalid command.
ftp> cd webroot
530 Please login with USER and PASS.
ftp> cd temp
530 Please login with USER and PASS.
ftp> ascii
530 Please login with USER and PASS.
ftp> send C:\updextipres_neverstill.txt
530 Please login with USER and PASS.
530 Please login with USER and PASS.
ftp> bye
221
</console output>

Does anyone know what I'm doing wrong? I'm creating the script so that I
can use variables with FTP.exe.
Thanks for any help or ideas!

Steve

Pegasus \(MVP\)
07-09-2005, 11:35 PM
"Steve" <sss@sss.com> wrote in message
news:%23On0KJIXFHA.2664@TK2MSFTNGP15.phx.gbl...
> Trying to make a batch file that will handle some FTP tasks for me.
> I have a batch file that creates a FTP script file.
>
> Here is the batch file:
> <code>
> @echo off
> :: Execute the ping and store results in tmp file
> SET RESULTS=C:\updextipres_neverstill.txt
> ping -r 1 -n 1 www.yahoo.com > %RESULTS%
>
>
> :: Create FTP script for this site
> SET FTPSCRIPT="C:\FTPScript.txt"
>
> ECHO open ftp19.******.com > %FTPSCRIPT%
> ECHO ******* >> %FTPSCRIPT%
> ECHO ****** >> %FTPSCRIPT%
> ECHO cd webroot >> %FTPSCRIPT%
> ECHO cd temp >> %FTPSCRIPT%
> ECHO ascii >> %FTPSCRIPT%
> ECHO send %RESULTS% >> %FTPSCRIPT%
> ECHO bye >> %FTPSCRIPT%
>
> :: Execute ftp using script
> %windir%\system32\ftp.exe -n -s:%FTPSCRIPT%
>
> :: Cleanup tmp files
> del %FTPSCRIPT%
> del %RESULTS%
> @echo off
> </code>
>
> This create the script file that looks like this:
> <code>
> open ftp19.******.com
> username
> password
> cd webroot
> cd temp
> ascii
> send C:\updextipres_neverstill.txt
> bye
> </code>
>
>
> When I run the batch file, this is what I get:
> <console output>
> C:\>update_external_ip.bat
> ftp> open ftp19.********.com
> Connected to ftp19.brinkster.com.
> 220 Microsoft FTP Service
> ftp> brinkusername Invalid command.
> ftp> password Invalid command.
> ftp> cd webroot
> 530 Please login with USER and PASS.
> ftp> cd temp
> 530 Please login with USER and PASS.
> ftp> ascii
> 530 Please login with USER and PASS.
> ftp> send C:\updextipres_neverstill.txt
> 530 Please login with USER and PASS.
> 530 Please login with USER and PASS.
> ftp> bye
> 221
> </console output>
>
> Does anyone know what I'm doing wrong? I'm creating the script so that I
> can use variables with FTP.exe.
> Thanks for any help or ideas!
>
> Steve
>
>

Run your ftp command like so:

%windir%\system32\ftp.exe -s:%FTPSCRIPT% ftp19.********.com

and remove the "open" line from your script. You might also want
to run FTP in binary rather than ASCII mode - ASCII can turn
CRLFs into CRs.

Mark Dormer
07-09-2005, 11:35 PM
Remove the -n parameter

%windir%\system32\ftp.exe -n -s:%FTPSCRIPT%
%windir%\system32\ftp.exe -s:%FTPSCRIPT%

And lose the spaces, it stuffs up the login.
It tries to login an "******* "

> ECHO open ****** > %FTPSCRIPT%
> ECHO ***** >> %FTPSCRIPT%
> ECHO ****** >> %FTPSCRIPT%
> ECHO cd pub >> %FTPSCRIPT%
> ECHO cd temp >> %FTPSCRIPT%
> ECHO ascii >> %FTPSCRIPT%
> ECHO send %RESULTS% >> %FTPSCRIPT%
> ECHO bye >> %FTPSCRIPT%

ECHO open ******> %FTPSCRIPT%
ECHO *****>> %FTPSCRIPT%
ECHO ******>> %FTPSCRIPT%
ECHO cd pub>> %FTPSCRIPT%
ECHO cd temp>> %FTPSCRIPT%
ECHO ascii>> %FTPSCRIPT%
ECHO send %RESULTS%>> %FTPSCRIPT%
ECHO bye>> %FTPSCRIPT%


__________________________________________

This one works,. just change the server, user and password
----------------------------------------------

@echo off
:: Execute the ping and store results in tmp file
SET RESULTS=C:\updextipres_neverstill.txt
ping -r 1 -n 1 www.yahoo.com > %RESULTS%


:: Create FTP script for this site
SET FTPSCRIPT="C:\FTPScript.txt"

ECHO open your.ftp.server> %FTPSCRIPT%
ECHO username>>%FTPSCRIPT%
ECHO password>>%FTPSCRIPT%
ECHO cd pub>>%FTPSCRIPT%
ECHO cd temp>>%FTPSCRIPT%
ECHO ascii>>%FTPSCRIPT%
ECHO send %RESULTS%>>%FTPSCRIPT%
ECHO bye>>%FTPSCRIPT%


:: Execute ftp using script
%windir%\system32\ftp.exe -s:%FTPSCRIPT%

:: Cleanup tmp files
rem del %FTPSCRIPT%
rem del %RESULTS%
@echo off

_______________________________________________________________

Regards
Mark Dormer


"Steve" <sss@sss.com> wrote in message
news:%23On0KJIXFHA.2664@TK2MSFTNGP15.phx.gbl...
> Trying to make a batch file that will handle some FTP tasks for me.
> I have a batch file that creates a FTP script file.
>
> Here is the batch file:
> <code>
> @echo off
> :: Execute the ping and store results in tmp file
> SET RESULTS=C:\updextipres_neverstill.txt
> ping -r 1 -n 1 www.yahoo.com > %RESULTS%
>
>
> :: Create FTP script for this site
> SET FTPSCRIPT="C:\FTPScript.txt"
>
> ECHO open ****** > %FTPSCRIPT%
> ECHO ***** >> %FTPSCRIPT%
> ECHO ****** >> %FTPSCRIPT%
> ECHO cd pub >> %FTPSCRIPT%
> ECHO cd temp >> %FTPSCRIPT%
> ECHO ascii >> %FTPSCRIPT%
> ECHO send %RESULTS% >> %FTPSCRIPT%
> ECHO bye >> %FTPSCRIPT%
>
> :: Execute ftp using script
> %windir%\system32\ftp.exe -n -s:%FTPSCRIPT%
>
> :: Cleanup tmp files
> del %FTPSCRIPT%
> del %RESULTS%
> @echo off
> </code>
>
> This create the script file that looks like this:
> <code>
> open ftp19.******.com
> username
> password
> cd webroot
> cd temp
> ascii
> send C:\updextipres_neverstill.txt
> bye
> </code>
>
>
> When I run the batch file, this is what I get:
> <console output>
> C:\>update_external_ip.bat
> ftp> open ftp19.********.com
> Connected to ftp19.brinkster.com.
> 220 Microsoft FTP Service
> ftp> brinkusername Invalid command.
> ftp> password Invalid command.
> ftp> cd webroot
> 530 Please login with USER and PASS.
> ftp> cd temp
> 530 Please login with USER and PASS.
> ftp> ascii
> 530 Please login with USER and PASS.
> ftp> send C:\updextipres_neverstill.txt
> 530 Please login with USER and PASS.
> 530 Please login with USER and PASS.
> ftp> bye
> 221
> </console output>
>
> Does anyone know what I'm doing wrong? I'm creating the script so that I
> can use variables with FTP.exe.
> Thanks for any help or ideas!
>
> Steve
>
>


Emulated DOS FTP script ?