I can connect and get, but am having fits trying to figure out how to process the directory listing.
Below is the code I have. I have tried calling a subroutine from in sftp->ls and other things. No luck. Any suggestions would be welcome.
#!/var/opt/pgpdba/perl/bin/perl #use strict; use Net::SFTP; use Net::SFTP::Attributes; use Logger; use Platform; use Getopt::Std; use File::Basename; $0 =~ s/^.*(\/|\\)//; # Strip a path if it is exists my $root = $0; $root =~ s/\..*$//; # Clean up script name my $LOG_FILE = "./${root}.log"; getopts('hr:l:'); print_usage_and_quit() if ($opt_h); my $CREDFILE = "./user.txt"; my $host=""; my $user=""; my $password=""; my $rdir=$opt_r; my $ldir=$opt_l; openlog("$LOG_FILE"); load_credentials(); my $sftp = Net::SFTP->new($host, user => $user, password => $password, debug => 1); #my $attrs = Net::SFTP::Attributes->new(Stat => [ stat "./session_moni +tor.sql" ]); #my $size = $attrs->size; #print "$size\n"; #exit; $sftp->ls($rdir,sub{print "$_[0]->{filename}\n"}) ; #@listing = $sftp->ls($rdir,); #foreach(@listing) #{ # print "$_\n"; #}*/ #$sftp->do_lstat("oc") ; #$sftp->get("$rdir/*", "$ldir/*"); #$sftp->put("bar", "baz"); sub getfile ($filestuff) { if ($_[0]->{filename} ne '.' && $_[0]->{filename} ne '..' && $ +_[0]->{filename} ne 'processed') { print "1 - $filestuff\n" #$sftp->get("$rdir/".$_[0]->{filename}, "$ldir/".$_[0] +->{filename}); } } sub load_credentials { open (CREDFILE1, "<$CREDFILE") or quittext_opc "Can't open credentials file $CREDFILE\n" +, $AP_CNA, $SEV1, $GRP3, "1010", $STAT1; #die "Can't open credentials file $CREDFILE\n"; while (<CREDFILE1>) { # next if /^\s*(?:#|$)/; + # ignore comments/ blank lines chomp; my @fields = split /:/; if ($fields[0] eq 'user') { $user=$fields[1]; } if ($fields[0] eq 'pwd') { $password=$fields[1]; } if ($fields[0] eq 'host') { $host=$fields[1]; } } return 0; }
I didn't include the print_usage_and_quit sub....
Edited by davido: Added readmore tags.
In reply to using sftp to get file information for processing by jblapham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |