Hi All,

I am trying to create a SFTP handle and then switch the working directory and put a file into that new directory. I am able to switch directories (at least it does not die) but the file does not get uploaded into that directory. When uploading to the root directory, it works as expected.

I am not very familiar with objects and references and am fairly new to perl. I did look through the example directory of the Net::SFTP module, but didn't find or understand my answer. Am I supposed to initiate a shell for this somehow? Here is the relevant code I am trying to get to work

sub connect_sftp { #Only takes 2 arguments, host scalar, and args my $host = shift @_; my %args; while (@_){ my $key = shift; my $value = shift; $args{$key}=$value; } print "Getting SFTP file handle for $host..." if ($debug); my $sftp_handle = Net::SFTP->new($host,%args); print "Success!\n" if ($debug); return $sftp_handle; } #LATER IN SCRIPT my $sftp_path = "incoming" if ("$sftp_path" ne "/"){ print "About to switch to $sftp_path d +irectory...\n" if ($debug); $sftp_handle->do_opendir("$sftp_path") + or die "Could not change cwd to $sftp_path\n"; } print "About to send $file_path$isbn.$type to +$distributor at $sftp_path$isbn.$type\n" if ($debug); $sftp_handle->put("$file_path$isbn.$type","$is +bn.$type") or die "SFTP Transfer Error: Tried to sen +d $file_path$isbn.$type to $distributor at $sftp_path$isbn.$type\n";

In reply to 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.