in reply to question about objects / Net::SFTP

Hi, with Sftp you have to be very careful about using full directory paths, or be very certain of your cwd on both ends of the connection. Try something like this. Notice the full file path in the put method.

Finally, try connecting with the sftp program of your choice, like sftp, and watch what steps you must take, in changing directories and what your pwd is.

#!/usr/bin/perl use warnings; use strict; use Net::SFTP; #Who am I and where am I going? my $user = 'z'; my $pass = 'zpass'; my $sftp; my $file = "test.txt"; my $put_to_dir = "/home/z/2"; my $put_from = $0; #upload this file my $host = '0.0.0.0'; my $result; #Where the real action takes place... $sftp = Net::SFTP->new($host, "user" => $user, "password" => $pass, ) or die "Can't login $!\n"; $sftp->put($put_from, "$put_to_dir/$file") || die "Can't open $!\n"; my @AOH = $sftp->ls($put_to_dir); foreach my $href(@AOH){ foreach my $key( %{$href} ){ if(defined ${$href}{$key}){ if( ${$href}{$key} =~ /-rwxr-xr-x(.*)$file$/ ){ $result = ${$href}{$key}; } } } } # Writting log files for transfers open LOGS, ">> $0.log" or die "Can't open file, $!\n"; # Get my dates my $date; my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5]; $year=$year+1900; $mon=$mon+1; $date = sprintf("%02d%02d%02d", $year,$mon,$mday); # # Write my logs so I can track myself print LOGS "Transfer date:$date, File transfered:$put_to_dir/$file\n$result\n"; close LOGS;
Also, since you are new, why not try using Net::SSH2, as it has sftp built in. See A little demo for Net::SSH2

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh