On 09 Jul 2002 20:20:38 +0200
henjay
I'm looking for a script that will do the following. 1: Connect to a FTP site. 2: Connect automatically either using cron or running the script manually (username and password in the script or in seperate file). 3: Download an "X" number of files. (The file names are already known) 3a: Download an "X" number of files but this time the file names are not known. 4: Backup the already existing files and copy the files to a backup directory. The name of the directory is the name of the file including the date. 5: Copy the new files from the FTP site to the specified directory.
And last but not least. Is there a good site where I can go too to learn Shell scripting and also a good book for someone who has never programmed before?
If you want to learn bash shell scripting, try http://www.shelldorado.com it has books, examples, everything. Your particular script would probably be easier in Perl, bash is very clunky for doing anything other than basic system commands. Here is a quick sample script using the Net::Ftp module from Perl. If you need help with the backing-up portion of the script, I would go to www.perlmonks.org and post the question, showing what you have written so far. This script will give you something to play with, you can call it from a bash script, if you want to do the backup portion in bash. You can get Net::FTP from http://cpan.org Perl has a File::Path module which makes creating directories easy, and File::Copy which make copying and moving easy. This script assumes ascii files, but you can change it to binary. ####################################################### #!/usr/bin/perl use Net::FTP; $username='username'; $password='password'; @filename=('1.txt','2.txt','3.txt','4.txt'); $rdir='/PATH_TO_FILES'; $ftp=Net::FTP->new("ftp.myftp.com") or print "Can-t connect $@\n"; $ftp->login($username,$password) or print "Can-t login\n"; $ftp->cwd($rdir) or print "Can-t cd\n"; $ftp->ascii(); foreach my $f (@filename) { $ftp->get($f); } $ftp->quit(); exit; ########################################################## -- use Perl; #powerful programmable prestidigitation