How to execute a batch file containing ftp commands??

hi,

is there a way i can execute a batch file containing ftp commands like we execute sftp batch file.

sftp -b batchfile user@server > output

how to create a batch file for ftp executing command and how to run the batch file from a shell script?

Just asking, why would you prefer ftp while sftp provides more functionality?

As afaik ftp doesnt support 'batchfile processing', on linux at least.
In which case i'd use:

ftp user@domain > output << EOF
ls
bye
EOF

Hope this helps

I will agree with sea that sftp would be better, but I assume that the target doesn't support it.

Could I suggest that you change the code to this to ensure that the credentials are not displayed for anyone to see with a ps -ef | grep ftp :-

ftp -nv $targethost << EOFTP >$logfile.$$
user $userid $password
cd $targetdirectory
get or put command here
quit
EOFTP

Long running FTP jobs can give far too much away to a curious user. We have our set so that every transfer has it's own set of credentials and target directory. That way if we need to change a password, then only one transfer is affected. It's a pain to stick to, but the impact of a required change makes it worthwhile.

Using $logfile.$$ also allows you to keep a history of FTP attempts in case you are re-running or have many processes that use the same basic script. You can read the log file looking for errors or success as required. make sure that you have a process to tidy them away later on.

Robin
Liverpool/Blackburn
UK