≡ Menu

Shell script to copy all files recursively and upload them to remote FTP server

{ 18 comments… add one }
  • Rahul August 7, 2012, 4:51 pm

    Hi All,
    We are using commaand as,

    /usr/bin/ncftpput -u $username -p $passwd

    But it does not overwrite file on remote server if it already present.
    Any suggestions???

  • Astral May 2, 2012, 2:08 pm

    Fantastic! Thanks !

  • andrew April 23, 2012, 5:11 am

    Is there a way to skip sir, it’s very important as I’m doing massive amount of files, and our destination server’s connection isn’t reliable. Cheers

  • Pavan November 14, 2011, 6:32 am

    hi , I have shell script to sftp the files from one server to other server. When executed manually it works fine but when scheduled the script using crontab it fails.
    Below is the piece of code. Please help me in solving this issue. Thanks in advance.

     dt=`date +%Y%m%d`
     fldt=`date --date "$dt 1 days ago" +%Y%m%d`
    sudo -u xyz sftp $USER@$HOST <<EOF
     cd rmtdir
     mget filename_$fldt*.dat.txt $ldir
     if [ $? -ne 0 ]; then
     echo "sftp failed" | mailx -s "`date` :Sftp failed" pavan@ymail.com
     echo "sftp success"| mailx -s "`date` :Sftp success" pavan@ymail.com
     exit 0
    • Goksel December 24, 2011, 10:46 am

      /usr/bin/sudo -u xyz /usr/bin/sftp

  • Gaurab August 5, 2010, 5:42 am

    Can all the files zipped in a single zip file before copying to other remoter server.

  • Pelle May 3, 2010, 5:21 pm

    I hade to delete “$myf” in the line below:
    CMD=”$FTP -m -R -f $AUTHFILE $myf $remotedir $localdir”

    Then it all went well.

    Thank you for an good and simple script!

  • Brendon February 13, 2010, 11:32 am

    How can I make this GET the remote files. Obviously I used it to send them all there – now how can I send my 100GB back to the server?

  • jamuna December 24, 2009, 7:20 am

    HI please explain it

    [ “$remotedir” == “” ] && remotedir=”/” || :
    [ “$localdir” == “” ] && localdir=”.” || :

  • Fred THL December 21, 2009, 12:22 pm

    Why not considering rsync over ssh ?

  • BJones December 13, 2009, 8:30 pm

    Can we add this script to cron and have it auto backup? I am looking to back up entire dir every week, like at 3am, when there is the least amount of traffic, but I don’t want to have to be around for this to happen.

  • Rotx September 10, 2009, 9:46 am

    I am taking server name from a file and everything working fine buy my problem is if a server in the list is not connecting it is not going to next available server. How to get the ftp status in the script if ftp is not connecting how to skip to next available server .

  • Dabidi July 8, 2009, 9:16 am

    How to skip upload existing files on remote server?

  • me May 19, 2009, 12:12 pm

    If using the AUTHFILE option, don’t forget to set the following variables in this script


    And yes, you will need ncftp installed, if it is not already
    For OS X with mac ports,
    sudo port install ncftp

  • me May 19, 2009, 11:13 am

    I love you!

  • elejido April 22, 2009, 10:16 pm

    If the SAME file exists in the remote server, the script overwrite it? append? resume?

  • O2Link April 20, 2008, 11:56 am

    Thank you!
    it was so usefull for my work.

Security: Are you a robot or human?

Leave a Comment