
shawnhcorey
Enthusiast

Sep 26, 2008, 5:48 PM
Post #2 of 5
(749 views)
|
|
Re: [Spence32] FTP files from multiple source directories to multiple target directories
[In reply to]
|
Can't Post
|
|
Hi, I am looking to create a Perl script to FTP files from multiple source directories to multiple target directories, with each source directory is mapped to a particular target directory. For example, FTP all files from source dir 100 to target dir 100, source 200 to target 200, etc. Here is a script I am working from for a single file: use Net::FTP; chdir "/tmp"; $ftp = Net::FTP->new("host", Debug => 0); $ftp->login("username",'-password@'); $ftp->cwd("/dir"); $ftp->get("the.file"); $ftp->quit; I know I need to use a loop, but I am not quite sure of how to use it without defining multiple variables for each directory. Any suggestions? Thanks In you want just the files in one directory, use glob (see `perldoc -f glob`). If you want the subdirectories too, use File::Find (see `perldoc File::Find`). Something like this:
for my $file ( glob( $dir ) ){ next unless -f $file; # skip all but regular files # ftp the file } __END__ I love Perl; it's the only language where you can bless your thingy. Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib. Get Markup Help. Please note the markup tag of "code".
|