Download multiple files from ftp server with bash script

9,865

You could cd into the directory then use mget command to get all files in that directory:

ftp -in ftp://user:[email protected] << EOF
    binary
    cd Datenbankbackup
    mget *
EOF
Share:
9,865

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I have 2 or 3 FTP Servers where our hoster puts database backups each day. Since he only keeps one, I was orded to write a bash script for downloading alle database backups every day so we have more than the one day old backup.

    I tried to get it working with ftp command, but since it seems I can't download an complete directory I thought I could do it with a for loop but that won't work with the ftp command and I always get an unxpected end of file error.

    I should say, only can connect via ftp on the server. No SSH access or something else!

    At the moment I have this:

    echo "Download all the database backups from honds ftp-servers"
    
    SERVERS="ftp.srv1.de ftp.srv2.de"
    
    #for SERVER in $SERVERS; do
        ftp -in ftp://user:[email protected] << EOF
        binary
        get Datenbankbackup
    EOF
    
    • Admin
      Admin over 9 years
      Well would be a good Idea, but I don't have access via ssh to the ftp server. I can only connect via the ftp command or any other ftp client. And via the ftp command I can't tar the files.
    • Admin
      Admin over 9 years
      Yeah sorry, I forget that. I edited that already.
  • Admin
    Admin over 9 years
    Well, that was pretty obviously, why didn't I thought about that... thanks, does what it should