How I can use variables in ftp? This is what have i done: file a.bat:
set file=test
ftp -s:b.txt IP
file b.txt
user
password
get %
The reason the %-artifact didn't work in the BAT file was that that token was never seen and replaced. Just as in a UNIX shell script, $-substitutions are performed when those lines are collected and tokenized. Since the line containing the %file% was input to FTP, it was collected and parsed by FTP, not by the "DOS" shell.
In UNIX, you can solve this problem by piping the directives through FTP. That is to say, while this (where $1 is a filename parameter supplied on the command line):
ftp << FTP_CMDS
user joe
pass joesPassword
get $1
quit
FTP_CMDS
wouldn't work, THIS:
(echo user joe;
echo pass joesPassword;
echo get $1;
echo quit ) | ftp
WOULD work.