How to ftp multiple files by taking the file name from a input file.

Hi,

I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt.

vi input.txt
 
abc.c
welcome.c
new.c
welcome1.c

for ftp'ing a single file say 'new.c' the following code works fine.

    
    HOST="xxxxxx"
    USER='xxxxxxx'
    PASSWD='xxxxxx'
    FILE="new.c"
    ftp -inv $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    cd $trgtpath
    lcd $curnt_dir
    binary
    prompt off
    mget $FILE
    bye
    ##quit
    END_SCRIPT
    ##exit 0

Please help me with looping through input.txt file and copying the files.

Also pls share the info on what <<END_SCRIPT signifies.

Thanks,
Srini

<<END_SCRIPT --> google "here document + shell script"

Here Documents

 
HOST="xxxxxx"
USER='xxxxxxx'
PASSWD='xxxxxx'
while read FILE
do
ftp -inv $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $trgtpath
lcd $curnt_dir
binary
prompt off
mget $FILE
bye
END_SCRIPT
done < input.txt
1 Like

maybe try this but while or for loop is the best way.

FILE=$(sed ':a;$!N;s/\n/ /;ta;s/   */ /g' input.txt)