in reply to Re: ftp put problem!
in thread ftp put problem!

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;

Replies are listed 'Best First'.
Re^3: ftp put problem!
by runrig (Abbot) on Jul 29, 2008 at 21:00 UTC
    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;
        Get in the habit of using strict and warnings (this would have caught at least one of your problems in the code above). I don't see any reason to use File::Listing here. Use <code></code> tags around your code posted here. Also, I don't get whether you just want to send all files in a directory or it's subdirectories also. Here is something that does just one directory:
        #!/usr/bin/perl use strict; use warnings; use Net::FTP; my $host = 'ServerName'; my $ftp = Net::FTP->new($host, Timeout => 1800) or die "Cannot contact + $host: $!"; $ftp->login('ID', 'PWD') or die "Cannot login ($host):" . $ftp->messag +e; my $dir = '/path/to/files'; chdir $dir or die "Can't cd to $dir: $!"; # E.g., all txt files my @files= grep -f, <*.txt>; foreach $file (@files) { $ftp->put($file) or warn "Could not put $file: ".$ftp->message(); } $ftp->quit; exit;