kurt2439 has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: question about objects / Net::SFTP
by zentara (Cardinal) on Jan 28, 2011 at 17:23 UTC | |
|
Re: question about objects / Net::SFTP
by Khen1950fx (Canon) on Jan 28, 2011 at 19:35 UTC | |
by salva (Canon) on Jan 28, 2011 at 20:51 UTC | |
|
Re: question about objects / Net::SFTP
by salva (Canon) on Jan 28, 2011 at 20:49 UTC | |
by kurt2439 (Sexton) on Jan 29, 2011 at 00:55 UTC |