I need to upload the entire content of a directory /home/test to my ftp server, in a specific folder. I will then schedule the script hourly via cron. Any examples?

NB. consider that I'm on a Netgear ReadyNAS Duo (a debian box) and I can't install lftp or similars, only standard commands :)

link|improve this question

What do you mean "standard commands"? Bash has no "standard command" for ftp. – DerfK Jun 10 '11 at 14:38
Is the Netgear ReadyNAS Duo the machine you want to copy from or to? You are unable to install any sort of software or run scripts on it? Is there a possibility of initiating the connection on the FTP server and pulling down the files? – Clinton Blackmore Jun 10 '11 at 15:25
feedback

5 Answers

up vote 0 down vote accepted

Found this bash script online that has quality documentation:

#!/bin/bash

HOST=ftp.server.com  #This is the FTP servers host or IP address.
USER=ftpuser             #This is the FTP user that has access to the server.
PASS=password          #This is the password for the FTP user.

# Call 1. Uses the ftp command with the -inv switches.  -i turns off interactive     prompting. -n Restrains FTP from attempting the auto-login feature. -v enables verbose and progress. 

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS

# Call 3. Here you will change to the directory where you want to put or get
cd /path/to/file

# Call4.  Here you will tell FTP to put or get the file.
put test.txt

# End FTP Connection
bye

After configuring and saving the .sh script, make it executable:

chmod +x ftpscript.sh

Lastly, configure your cronjob

link|improve this answer
this is the correct answer. thanks. – Fabio B. Jun 13 '11 at 9:26
feedback

If ssh is installed and configured to allow file transfers you could use scp.

If not netcat or rsync may be an option.

link|improve this answer
no way. I have to make it work with ftp. – Fabio B. Jun 10 '11 at 15:16
feedback

if you have 'curl', which is fairly standard, it can do unattended FTP uploads (see man page for the -T option)

link|improve this answer
feedback

If you are able to install or build programs, a utility called ftpsync may be just what you are looking for. [I've never tried it, and there seem to be several utilities either called that or something very similar.]

link|improve this answer
feedback

In a bash script you should be able to do something like:

    #!/bin/bash
    echo "
    verbose
    open 1.2.3.4
    USER ftpuser ftppasswd
    put /path/to/stuff.tar.gz
    bye
    " > ftp -n > ftp_$$.log

Tarring your directory first would be a good idea and make it much simpler. Also, depending on the size of your directory and the speed of your network, you may want to consider doing differential tars.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.