October 30th, 2007, 01:31 PM
-
Cannot login into SFTP server using Net::SFTP
hi
we're using Public/Private Key authentication between SFTP client and server to trnasfer files.
I can login into SFTP server from my client linux debian machine without problems using this command:
# sftp user@server (without password)
but if i try to use a Net::SFTP perl script it doesn't work:
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::SFTP;
my $server="X.X.X.X";
my $user="myuser";
my $password="";
my %args = (user => "$user", password => "$password", ssh_args => [port => 22]);
my $file="TEST.CSV";
my $sftp=Net::SFTP->new($server, %args);
$sftp->put($file);
exit;
TEST.CSV is there, at the same directory.
I get the following error:
Code:
# perl test.cgi
Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Net/SFTP.pm line 245.
Couldn't get handle: No such file or directory at test.cgi line 20
howto solve this problem ?
Last edited by ccc; October 30th, 2007 at 03:39 PM.
October 30th, 2007, 03:07 PM
-
$sftp->put($local, $remote [, \&callback ])
Callback is optional, but I don't think the name for the remote file is. Try specifying both $local and $remote.
October 30th, 2007, 03:38 PM
-
I changed the script to:
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::SFTP;
my $server="X:X:X:X";
my $user="statravel";
my $password="";
my %args = (user => "$user", password => "$password", ssh_args => []);
$args{debug} = 1;
$args{user} = "myuser";
my $file="TEST.CSV";
my $sftp=Net::SFTP->new($server, %args) or die "could not open connection to $server\n";
$sftp->put($file, $remote [, \&callback ]) or die "could not upload a file\n";
exit;
but get the following error now:
Code:
# perl test.cgi
Multidimensional syntax $remote [, \&callback ] not supported at test.cgi line 24.
Global symbol "@remote" requires explicit package name at test.cgi line 24.
syntax error at test.cgi line 24, near "[,"
Execution of test.cgi aborted due to compilation errors.
October 30th, 2007, 03:40 PM
-
Sorry I wasn't clear. Get rid of this part: [, \&callback ]
That came from the documentation where the brackets in that context mean an optional argument.
All you should need is
Code:
$sftp->put($file, $remote);
You need to define $remote. This might work:
Code:
$sftp->put($file, $file);
October 30th, 2007, 04:04 PM
-
thanks a lot, now it works well !
March 14th, 2013, 10:05 AM
-
need help with script
hi, can you please share your final script which is working. Also do i need to install additional libraries in unix to run this script???