in reply to ftp put problem!

You don't even nead readdir if all you want is a listing. That's what the backtick operator is for:
#!/usr/bin/perl use Net::FTP; use File::Listing qw(parse_dir); $host = 'ServerName'; $path = '/home/'; $ftp = Net::FTP->new($host, Timeout => 1800) or die "Cannot contact $h +ost: $!"; $ftp->login('ID', 'PWD') or die "Cannot login ($host):" . $ftp->messag +e; $ftp->cwd($path) or die "Cannot change directory ($host):" . $ftp->mes +sage; #@Files = $ftp->ls('-lR'); @Files = 'ls -l'; #@Files = `ls -l $path' if $path is what you want a listing of #$ftp->binary(); #$ftp->ascii(); foreach $file (parse_dir(\@Files)) { my($name, $type, $size, $mtime, $mode) = @$file; $ftp->put("$name") or warn "Could not get $name, skipped: $!"; } $ftp->quit; exit;

Replies are listed 'Best First'.
Re^2: ftp put problem!
by bbi (Initiate) on Jul 29, 2008 at 20:42 UTC
    The script seems to run fine but the files are not transferred over to the remote server. It's suppose to do a ls -l then grab the files, parse and ftp. thanks
    #!/usr/bin/perl
    use Net::FTP;
    use File::Listing qw(parse_dir);
    $host = 'hostname';
    #$path = 'path/';
    $ftp = Net::FTP->new($host, Timeout => 1800) or die "Cannot contact $host: $!";
    $ftp->login('ID', 'pwd') or die "Cannot login ($host):" . $ftp->message;
    #$ftp->cwd($path) or die "Cannot change directory ($host):" . $ftp->message;
    #Files = `dir *.txt`;
    #$ftp->binary();
    #$ftp->ascii();
    @Files= `ls -lR`;
    foreach $file (parse_dir($Files))
    {
    my($name, $type, $size, $mtime, $mode) = @$file;
    $ftp->get ($name) or warn "Could not get $name, skipped: $!";
    }
    $ftp->quit;
    exit;
      You are get()'ing the files...I thought you wanted to put()?
        Sorry, confusing myself since I have several versions. Here is the script i'm trying to get working.
        #!/usr/bin/perl
        use Net::FTP;
        use File::Listing qw(parse_dir);
        $host = 'ServerName';
        #$path = 'DestinationPath';
        $ftp = Net::FTP->new($host, Timeout => 1800) or die "Cannot contact $host: $!";
        $ftp->login('ID', 'PWD') or die "Cannot login ($host):" . $ftp->message;
        #$ftp->cwd($path) or die "Cannot change directory ($host):" . $ftp->message;
        #Files = `dir *.txt`;
        #$ftp->binary();
        #$ftp->ascii();
        @Files= `ls -lR`;
        foreach $file (parse_dir($Files))
        {
        my($name, $type, $size, $mtime, $mode) = @$file;
        $ftp->put($name) or warn "Could not put $name: ".$ftp->message();
        }
        $ftp->quit;
        exit;