0
votes

I want to download multiple files from ftp with a shell script. Up to now I always had all the files in one folder "/data". I used this script:

#!/bin/sh
HOST='abc.de'
USER='abc'
PASSWD='abc'
FILE='*.txt'
LOCDIR='/athome/abc/'
PATH='data/'

/usr/bin/ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $LOCDIR
prompt off
binary
ls
cd $PATH
mget $FILE
quit
END_SCRIPT
exit 0

Now I have multiple subfolders in the folder /data

/data
   /subfolder 1
      /file1
      /file2
   /subfolder 2
      /file1
      /file2
      /file3
...

how can I go through all these folders in a loop to download the containing files?

Thank you!

2

2 Answers

2
votes

use wget instead of mget like below

wget -r 'ftp://user:[email protected]/data'

user=abc pass=abc for your case

0
votes

just have a look to my script on https://github.com/thomasX/ftpBackup

with this you can download multiple folders from an ftp