Solved FTP Batch file - dynamically populating a variable

January 13, 2012 at 08:06:00
Specs: Windows 2003
I want to pass a filename to upload to a ftp.

I tried using a tempvar and also a command line parameter

set /p filename="Please enter filename "

@ftp -i -s:"%~f0"&GOTO:EOF
cd directory\test
mput %filename%

It is not working and fails at the mput command.
ftp> mput "%filename%"
%filename%:File not found

When i populated as a commandline argument by replacing the command as mput %1, it also failed.

Please let me know how to fix this or the correct way to populate that filename variable to upload.

See More: FTP Batch file - dynamically populating a variable

Report •

January 13, 2012 at 14:55:38
✔ Best Answer
There may be a more elegant way - but I would do:

@echo off
set /p filename="Please enter filename "

echo anonymous >ftpscript.dat
echo password >>ftpscript.dat
echo cd directory\test >>ftpscript.dat
echo ascii >>ftpscript.dat
echo mput "%filename%" >>ftpscript.dat
echo disconnect >>ftpscript.dat
echo bye >>ftpscript.dat

ftp -n -s:ftpscript.dat

del ftpscript.dat

Report •

January 17, 2012 at 04:09:12
The script worked fine in setting the file name but prompted with a Login Failure.

I get the below message
530-User cannot log in.
Win32 error: Logon failure: unknown user name or bad password.
Error details: An error occured during the authentication process.
530 End

Note - the login works perfectly when I pass that from an external file and fails when we pass through the dynamic file creation.

Report •

January 17, 2012 at 04:49:02
Fixed that by adding user, pass for the below and -i switch.
echo "USER" anonymous >ftpscript.dat
echo "PASS" password >>ftpscript.dat

ftp "-i" -n -s:ftpscript.dat

Thank You !

Report •

Related Solutions

Ask Question