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 directory...\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","$isbn.$type") or die "SFTP Transfer Error: Tried to send $file_path$isbn.$type to $distributor at $sftp_path$isbn.$type\n";