0: This very simple script is used to backup a
1: remote directory of tarred and zipped files.
2:
3: I'd be curous about better ways to do this.
4: In particular, I'm interested in a better
5: way to test if a remote file is a directory
6: or a file or a better way to determine if a file has already been copied<P>
7:
8: #~/usr/local/bin/perl -w
9:
10: use strict;
11: use Net::FTP;
12:
13: my $host='myhost.org';
14: my $uname='backup';
15: my $pword='really_secure';
16:
17: my $rdir='/backup';
18: my $ldir='D:/archives/brave-backup';
19:
20:
21: #########################################
22: # #
23: # no user server servicable parts below #
24: # #
25: #########################################
26:
27: my $ftp = Net::FTP->new($host, Debug => 0,
28: Passive =>1, Hash=>1)
29: or die("$@ couldn't construct ftp object");
30:
31: print "logging on to $host\n";
32: $ftp->login($uname,$pword)
33: or die("couldn't login to $host, as $uname\n");
34:
35: $ftp->cwd($rdir)
36: or die("couldn't cd to remote dir: $rdir\n");
37:
38: my @r_files=$ftp->ls()
39: or die("couldn't cd to list dir: $rdir\n");
40:
41: chdir($ldir)
42: or die("couldn't open to local dir: $ldir\n");
43:
44: opendir(DH,'.')
45: or die("couldn't cd to local dir: $ldir\n");
46:
47: my @l_files=readdir(DH)
48: or die ("couldn't list local dir: $ldir\n");
49:
50: closedir(DH)
51: or die("couldn't close local dir: $ldir");
52:
53: my %backed_up_files;
54: foreach (@l_files){
55: $backed_up_files{$_}=1;
56: }
57:
58: $ftp->binary()
59: or die("couldn't set mode to BINARY\n");
60: foreach(@r_files){
61:
62: if (!$backed_up_files{$_} && !Is_Dir($_)){
63: print "\tgetting $_\n";
64: $ftp->get($_)
65: or die("couldn't get remote file: $_");
66: }
67: }
68:
69: $ftp->quit;
70:
71: sub Is_Dir($){
72: my $maybe_dir=shift;
73: my $result=$ftp->cwd($maybe_dir);
74: $ftp->cwd($rdir); #return to our original dir
75: return $result;
76: } In reply to Net::FTP backup remote machine by mandog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |