Operating System - Linux
1828255 Members
2921 Online
109975 Solutions
New Discussion

Re: cannot login into the SFTP server using Net::SFTP

 
SOLVED
Go to solution
'chris'
Super Advisor

cannot login into the SFTP server using Net::SFTP

hi everyone

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 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:


#!/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;


I get the following error:

# 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 ?

7 REPLIES 7
Steven Schweda
Honored Contributor

Re: cannot login into the SFTP server using Net::SFTP

I know nothing, but if line 20 is this one:

$sftp->put($file);

and the complaint is "No such file or
directory", then I'd want to know if there
really is a "TEST.CSV".
'chris'
Super Advisor

Re: cannot login into the SFTP server using Net::SFTP

the file TEST.CSV is there !
Steven Schweda
Honored Contributor

Re: cannot login into the SFTP server using Net::SFTP

> the file TEST.CSV is there !

A transcript showing "ls -l" output would be
much more persuasive than your opinion/claim.
Evidence that you're looking at the same
directory as the script would also be nice.
'chris'
Super Advisor

Re: cannot login into the SFTP server using Net::SFTP

# ls -la
total 300
drwxr-xr-x 5 root root 4096 2007-10-30 20:15 .
drwxr-xr-x 28 root root 4096 2007-10-30 19:37 ..
-rw-r--r-- 1 root root 113280 2007-10-30 11:30 libmath-pari-perl_2.010709.orig.tar.gz
-rw-r--r-- 1 root root 9465 2007-10-29 20:31 libnet-sftp-perl_0.10-1.diff.gz
-rw-r--r-- 1 root root 392 2007-10-29 20:31 libnet-sftp-perl_0.10-1.dsc
-rw-r--r-- 1 root root 24676 2007-10-29 20:30 libnet-sftp-perl_0.10.orig.tar.gz
drwxrwxrwx 9 root root 4096 2007-10-30 11:30 Math-Pari-2.010709
drwxr-xr-x 7 500 500 4096 2007-10-30 11:31 Net-SFTP-0.10
drwxr-xr-x 6 linux linux 4096 2007-10-30 11:25 Net-SSH-Perl-1.24
-rw-r--r-- 1 root root 92276 2007-10-30 11:22 Net-SSH-Perl-1.24.tar.gz
-rw-r--r-- 1 root root 4233 2007-10-30 17:55 sftp.cgi
-rw-r--r-- 1 root root 4210 2007-10-30 11:47 sftp_old.cgi
-rw-r--r-- 1 root root 399 2007-10-30 20:14 test.cgi
-rw-r--r-- 1 root root 22 2007-10-29 14:13 TEST.CSV
'chris'
Super Advisor

Re: cannot login into the SFTP server using Net::SFTP

to put this file manually works without any problems:

# sftp myuser@X:X:X:X
Connecting to X:X:X:X...
sftp> put TEST.CSV
Uploading TEST.CSV to /HOME/TEST.CSV
TEST.CSV 100% 22 0.0KB/s 00:00
#
'chris'
Super Advisor

Re: cannot login into the SFTP server using Net::SFTP

this problem is solved now !

$sftp->put($file, $file) or die "could not upload a file\n";

greetings
chris
Ralph Grothe
Honored Contributor
Solution

Re: cannot login into the SFTP server using Net::SFTP

I wonder this script should have worked before.

Though I never have used this module Net::SFTP a quick look at its POD already in the SYNOPSIS section revealed that the module's put method requires at least two args, viz. local and remote file name.

http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm


Besides, this quoting of $user and $password shouldn't be necessary

my %args = (user => "$user", password => "$password",
Madness, thy name is system administration