LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-15-2006, 10:07 PM   #1
Spitty
LQ Newbie
 
Registered: Sep 2005
Location: Massachusetts
Distribution: Ubuntu 5.10
Posts: 3

Rep: Reputation: 0
Question Automating FTP upload via a shell script?


Hey all-

I'm trying to write a shell script that performs regular backups of a directory to a FTP server. I googled around a bit, and I found the following script in a howto:

#!/bin/sh
HOST='ftp server address'
USER='ftp username'
PASSWD='ftp password'
FILE='filename'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

Now, this is a good start, but I need this script to upload an entire directory, not just one file. So, my questions are:

-Using the basic ftp program for linux, is it possible to tell the ftp program to simply upload a directory? If so, is it possible for the script to go through the local directory and only upload those files that are newer than those on the server, or completely new?

-If it isn't, how do you script a shell script that recurses through a directory and just uploads every file it comes across via ftp, while mirroring the local file structure on the ftp?

Also, if anyone has a simpler method of doing this than with a shell script and ftp, that would be awesome too.

Thanks!
 
Old 01-16-2006, 03:12 PM   #2
halvy
Member
 
Registered: Aug 2005
Location: Boston Massachussets, USA
Distribution: my own Debian creation :)
Posts: 876

Rep: Reputation: 40
welcome spitty; why don't you look at how sbackup (simple backup ) does it,and maybe even try it

good luck.

Last edited by halvy; 01-16-2006 at 03:14 PM.
 
Old 01-16-2006, 05:57 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Is there any reason you have to use a basic ftp program? Life will be much easier if you can install ncftpput (part of the ncftp suite). Uploading a directory is pretty simply - I do my backups that way as well. The meat of the upload bit looks something like this:

ncftpput -S .tmp -DD -V -m -r $BACKUP_HOST backups $BACKUP_DIR

which says:

upload all of $BACKUP_DIR (because of the -r) to a directory on $BACKUP_HOST called "backups"
delete local files when done uploading (because of the -DD - you probably won't want this)
no output because we're running in a script (from -V)
don't overwrite destination files until the upload is done (from -S .tmp)
make the directory "backups" on $BACKUP_HOST if it doesn't already exist (from -m)

http://www.ncftp.com/

there's a lot of other useful ftp programs -
list the contents of an ftp dir and echo to stdout
get single file or directory (good for scripts as well)
and a nice interactive ftp client.

Last edited by BrianK; 01-16-2006 at 05:58 PM.
 
Old 01-16-2006, 06:40 PM   #4
halvy
Member
 
Registered: Aug 2005
Location: Boston Massachussets, USA
Distribution: my own Debian creation :)
Posts: 876

Rep: Reputation: 40
i forgot, since you are looking for 'regular' backups, sbackup has plenty of configurations for time/day, regular intervals, etc.

it even has ssh.. and the most important part is, IT WORKS!

i tried it.

it's origins are interesting as well.. it was developed last summer as some sort of google competition.. and it was so impresive that it made it's way right into the debian repositorys
 
Old 01-16-2006, 07:34 PM   #5
Spitty
LQ Newbie
 
Registered: Sep 2005
Location: Massachusetts
Distribution: Ubuntu 5.10
Posts: 3

Original Poster
Rep: Reputation: 0
Excellent! ncftpput seems to be exactly what I was looking for- my requirement of the normal ftp program was due to my ignorance of the existence of better things. sbackup would be good if the computer that is going to be running it had a gui, but alas, it's a console-only headless server- ncftpput seems like the better choice for that. That being said, I may very well get sbackup on my personal machine, as it seems like an excellent program.

Thanks for the help, BrianK and halvy- this time last night, I was thinking I would have to write some sort of nightmare recursive shell script- this is definitely much easier!
 
Old 01-16-2006, 10:28 PM   #6
halvy
Member
 
Registered: Aug 2005
Location: Boston Massachussets, USA
Distribution: my own Debian creation :)
Posts: 876

Rep: Reputation: 40
coool, backups are another thing lin needs to bone up on. i'v tried alota different backup progs and was awefully glad to stumble upon simpe-backup. i tried to setup bacula a coupla times, and i think they need to change the name to bitchula

hopefully you will be able to tear ncftpput and/or sbackup apart and see how it ticks so you can advance your scripting knowledge.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
automating lynx in a shell script yimboli Programming 15 04-04-2007 02:15 AM
Trouble when automating ftp with shell script hari_s_82 Linux - Newbie 2 09-23-2004 02:17 AM
Automating a playlist using shell script... DesiLILO Linux - Newbie 4 04-02-2004 11:03 PM
Connection, login and upload files to ftp server via shell script Paulo Ges Linux - Networking 2 02-21-2004 01:01 PM
FTP Script (Automating) noodle123 Linux - General 2 10-16-2002 08:17 AM


All times are GMT -5. The time now is 02:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration