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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |