Results 1 to 3 of 3

Thread: Scripting the backup of files from an FTP server

  1. #1
    Join Date
    Jun 2007
    Location
    Warrington, England
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    FIXED: Scripting the backup of files from an FTP server

    Hi,

    Admins, please move this thread if there is a better suited place

    I'm looking to make a script that will connect to an FTP server on my network, download a few directories to a local directory, and tar them up.

    I'm having some problems with the ftp command though. I've just about managed to connect to the FTP server using the FTP command, however I'm not too sure what to do next, let alone incorporate this into a script.

    Would anyone be able to give me some help on how to do this?

    Thanks,

    Joe
    Last edited by Barry Cent; May 5th, 2011 at 02:41 PM. Reason: Marked title of thread as fixed.

  2. #2
    Join Date
    Nov 2009
    Location
    Bristol, UK
    Beans
    148
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Scripting the backup of files from an FTP server

    maybe something like this

    Code:
    #!/bin/sh
    HOST='ftp.users.disorg.net'
    USER='yourid'
    PASSWD='yourpw'
    FILE='file.txt'
    LOCATION='/user1/data'
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    cd $LOCATION
    get $FILE
    quit
    END_SCRIPT
    exit 0
    Last edited by xifer; April 16th, 2010 at 10:55 PM.

  3. #3
    Join Date
    Jun 2007
    Location
    Warrington, England
    Beans
    38
    Distro
    Ubuntu 10.04 Lucid Lynx

    Talking Re: Scripting the backup of files from an FTP server

    Hey,

    Meant to update this thread much earlier, but only just got chance.

    Quote Originally Posted by xifer View Post
    maybe something like this

    Code:
    #!/bin/sh
    HOST='ftp.users.disorg.net'
    USER='yourid'
    PASSWD='yourpw'
    FILE='file.txt'
    LOCATION='/user1/data'
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    cd $LOCATION
    get $FILE
    quit
    END_SCRIPT
    exit 0
    xifer: Thanks very much for your reply. I was getting ready to give up before you replied!

    I was unable to use the script that you suggested to get ftp to do what I wanted.

    Whilst messing around with your script though, I came accross the utility 'lftp', which I was able to script to do exactly what I wanted!

    More information on lftp can be found here.

    I've basically used lftp to mirror the FTP server to a local directory, which I then tar, bzip and copy to an backup HDD.

    The following line is what I use to mirror a folder on the FTP server to the pwd:

    Code:
    lftp -c mirror ftp://<username>:<pass>@<FTP_IP>/<folder>/
    Thanks xifer for you time!

    Cheers,

    Joe

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •