Emulated DOS FTP script ?

S

Steve

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
 
P

Pegasus \(MVP\)

Steve said:
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.
 
M

Mark Dormer

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
 

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

Similar Threads

FTP question... 7
I can't connect to ftp server with ftp.exe 19
FTP question 4
Windows XP simple ftp batch ?? 0
How to login in FTP (Client) from batch? 1
FTP 530 Login Incorrect 1
Understandings a Batch file 4
Help about a script .bat 0

Top