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

In reply to Re: question about objects / Net::SFTP by zentara
in thread question about objects / Net::SFTP by kurt2439

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.