Need to send a file after I run a nightly cron to another server via SFTP/SSH. After doing a lot of reading here and other places I decided to forgo Net::SSH2 or Net::SFTP or Net::OpenSSH and went with: Net::OpenSSH::Compat::SSH2
It seems debug does not work. Anyway, I get a disconnect error at ->auth_password(). But, I can use Eclipse via ssh and sftp and login, I can use Winscp as well with the same credentials, so I know they are correct.
I am on - Ubuntu 12.04.1 LTS and I have OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
%connection_details = (
host => '<IP>',
user => '<USER>',
pass => '<PASS>',
port => '<PORT>',
);
$SFTP = &SFTP_connection(%connection_details);
exit (0);
sub SFTP_connection {
my (%connection_info) = @_;
use Net::OpenSSH::Compat::SSH2 qw(:supplant);
use Net::SSH2;
eval { require Net::SSH2; };
if ($@) {
print "The Net::SSH2 or Net::OpenSSH::Compat::SSH2 Perl module
+ is not installed on this server, which is required for this feature.
+\n
Please contact your server administrator and ask them t
+o install this module.\n";
return 0;
}
## Connect to the sFTP server
my $SFTP = Net::SSH2->new();
$SFTP->connect($connection_info{'host'},22)
or die "Unable to connect to the remote sFTP server \n\n $@";
## Login to sFTP server
$SFTP->auth_password($connection_info{'user'},$connection_info{'pa
+ss'})
or die "Unable to login Check username and password. \n\n $@\n
+";
return $SFTP;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|