Retrieving a List of files from Remote Server

Friday, May 17, 2013 , 0 Comments

Below is the perl script for retrieving the list of files from Remote server:

    use strict;
    use warnings;
    use Net::FTP;
    my $ftp_site     = 'localhost';
    my $ftp_dir      = '/home/simon/software';
    my $ftp_user     = 'a_login_name';
    my $ftp_password = 'a_password';
    my $glob         = 'ex*';
    my @remote_files;
    my $ftp = Net::FTP->new($ftp_site)
        or die "Could not connect to $ftp_site: $!";
    $ftp->login($ftp_user, $ftp_password)
        or die "Could not login to $ftp_site with user $ftp_user: $!";
        or die "Could not change remote working " .
                 "directory to $ftp_dir on $ftp_site";
    @remote_files = $ftp->ls($glob);
    foreach my $file (@remote_files) {
        print "Saw: $file\n";