Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

ftplist.pl

by jjdeterick (Curate)
on Feb 01, 2001 at 06:55 UTC ( [id://55635]=sourcecode: print w/replies, xml ) Need Help??
Category: FTP stuff
Author/Contact Info jjdeterick
Description: I'm new to perl, and this is one of my first attempts. I welcome any pointers on any easier/better ways to do this. Anyway, I hope this helps someone. Thanks, Enjoy
Program: ftp.pl                                        
Author: jjdeterick                                     
Date: 1/31/00                                          
Description:                                           
  This perl program will read a list of file names and
  get those files from a specified host.  The user    
  must first create a text list of the files to fetch 
  and enter the host, username, password and remote   
  directory that houses the files in the code.        
#!/usr/bin/perl -w
use Net::FTP;

$hostname = 'user defined';
$username = 'user defined';
$password = 'user defined';

$home = 'user defined';

# Open the FilesToGet.txt file which contains a list of files to be searched.
open(FilesToGet, ') { 
  $TheFile = $_;                         
  chomp($TheFile);                 
  $INFILE = $TheFile;

  $ftp = Net::FTP->new($hostname);
  $ftp->login($username, $password);

  $ftp ->cwd($home),"\n";

  #get the file
  $ftp->get($INFILE);

}

$ftp->quit;
Replies are listed 'Best First'.
Re: ftplist.pl
by a (Friar) on Feb 01, 2001 at 10:50 UTC
    Um, I'm hoping your cutnpaste lost something, but there's trouble between the open(FilesToGet, ' and the {, as it might be:
    open(FilesToGet, "FilesToGet.txt") or die "can't open FilesToGet.txt: $!"; while (<FilesToGet>) {
    and then you can skip
    $TheFile = $_; chomp($TheFile); $INFILE = $TheFile;
    and just do:
    chomp; $ftp->get($_);
    but to make life even easier:
    #!/usr/bin/perl -w use Net::FTP; use strict; my $hostname = 'user defined'; my $username = 'user defined'; my $password = 'user defined'; my $home = 'user defined'; my $debug = 5; open(FilesToGet, "FilesToGet.txt") or die "can't open FilesToGet.txt: $!"; my $ftp = Net::FTP->new($hostname); $ftp->login($username, $password); $ftp->cwd($home); while (<FilesToGet>) { print STDERR "Getting $_" if $debug > 3; chomp; $ftp->get($_); } $ftp->quit;

    a

Re: ftplist.pl
by enaco (Novice) on Nov 08, 2001 at 18:00 UTC

    I costumized the script to fit my needs, i hope you like it, it uses arrays and it also takes a hostlist as a argument

    I only coded perl for 1,5 week now, thats why its kind of ugly :o)

    #!/usr/bin/perl # # Entries in the file and host list should be seperated with # a new row. spaces or other signs will make the script fail. # You can use comments if you put a '#' sign in front of the # line, but it will make the printout of number of hosts and # files that are beeing backuped to show the wrong numbers. # use Net::FTP; use strict; my $usage = "$0 filelist hostlist username password directory\n"; my $filelist = $ARGV[0] or die "$usage"; my $hostlist = $ARGV[1] or die "$usage"; my $username = $ARGV[2] or die "$usage"; my $password = $ARGV[3] or die "$usage"; my $home = $ARGV[4] or die "$usage"; my $debug = 5; my @hostarr; my @filearr; my $nr = 0; open(FilesToGet, $filelist) or die "can't open filelist $filelist: $!\n"; open(HostsToGet, $hostlist) or die "can't open hostlist $hostlist: $!\n"; @hostarr = <HostsToGet>; chomp @hostarr; my $hostarrnr = @hostarr; @filearr = <FilesToGet>; chomp @filearr; my $filearrnr = @filearr; print "\nHosts: $hostarrnr\n"; print "Files: " . ($filearrnr * $hostarrnr) . "\n"; print "\n"; for (my $nr1 = 0; $nr1 < $hostarrnr; $nr1++) { next if ($hostarr[$nr1] =~ /^#/ | undef); print STDERR "Connecting to $hostarr[$nr1]\n" if $debug > 3; my $ftp = Net::FTP->new($hostarr[$nr1]); $ftp->login($username, $password); $ftp->cwd($home); for (my $nr2 = 0; $nr2 < $filearrnr; $nr2++) { next if ($filearr[$nr2] =~ /^#/ | undef); print STDERR "Getting $filearr[$nr2]\n" if $debug > 3; $ftp->get($filearr[$nr2],("$hostarr[$nr1]." . $filearr[$nr2])) +; } $ftp->quit; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://55635]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found