Linux - sh script - download multiple files from FTP -
i need script can download files ftp via sh code
i have use expect
ftp, if loop inside code, got
wrong # args: should "for start test next command" while executing "for v in "a b c""
my code
/usr/bin/expect << except_script set timeout 1 spawn ftp -n ${host} send "user ${user} ${passwd}\n" expect "ftp>" send "bin\n" expect "ftp>" send "dir\n" v in "${files_to_download[@]}" ftp_file="${v}.bz2" #download file echo ${ftp_file} #put code dl here done expect "ftp>" send "bye\n" except_script
wget
expect
can tricky work i'd prefer use gnu wget alternative. following should work long don’t have spaces in of arguments.
for v in "${files_to_download[@]}" ftp_file="${v}.bz2" wget --user=${user} --password=${passwd} ${host}/${ftp_file} done
request multiple resources using 1 ftp connection
if it’s issue, can avoid having make multiple ftp connections server using ftp globbing (wildcard characters), e.g.
wget --user=${user} --password=${passwd} "${host}/*.bz2"
make sure url quoted shell doesn’t expand wildcard. can use -nc, --no-clobber
option avoid re-downloading files have been downloaded.
on other hand, requesting multiple resources (wget url2 url2 ...
) does result in multiple ftp logins.
note: checked both of above operations monitoring port 21 on own ftp server tcpdump
.
ncftp
you may interested in ncftp. while haven’t used in years, found – , ncftpget
, ncftpput
utilities – easier use command line scripting standard unix ftp
program.
Comments
Post a Comment