prasanna14 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All , I am new to PERL , we are using SFTP to get the files from the remote server to our server .

I am able to do the SFTP to the remote server from commandline , but through PERL code i am getting errors.

I am using the Net::SFTP module, Please find the code i used below. i gave the password as null , since i am not using the password...

use Net::SFTP; my $host = 'HOST NUNBER'; my $user = 'USER ID'; my $password = ''; my $sftp = Net::SFTP->new($host,"user"=>$user,"password"=>$password,de +bug=>true); #$sftp->get("rolling_trade_report.csv");
i am getting the following error
"Permission denied at //pkgs/linux/intel/perl/5.8.0/lib/site_perl/5.8.0/Net/SFTP.pm line 62"
DEBUG Mode:
idwsit1m36: Reading configuration data /etrade/home/ibia_ir/.ssh/config
idwsit1m36: Reading configuration data /etc/ssh_config
idwsit1m36: Connecting to 217.154.215.76, port 22.
idwsit1m36: Remote protocol version 2.0, remote software version 1.82 sshlib: WinSSHD 4.23
idwsit1m36: Net::SSH::Perl Version 1.29, protocol version 2.0.
.dwsit1m36: No compat match: 1.82 sshlib: WinSSHD 4.23
idwsit1m36: Connection established.
idwsit1m36: Sent key-exchange init (KEXINIT), wait response.
idwsit1m36: Algorithms, c->s: 3des-cbc hmac-sha1 none
idwsit1m36: Algorithms, s->c: 3des-cbc hmac-sha1 none
idwsit1m36: Entering Diffie-Hellman Group 1 key exchange.
idwsit1m36: Sent DH public key, waiting for reply.
idwsit1m36: Received host key, type 'ssh-dss'.
idwsit1m36: Host '217.154.215.76' is known and matches the host key.
idwsit1m36: Computing shared secret key.
idwsit1m36: Verifying server signature.
idwsit1m36: Waiting for NEWKEYS message.
idwsit1m36: Enabling incoming encryption/MAC/compression.
idwsit1m36: Send NEWKEYS, enable outgoing encryption/MAC/compression.
idwsit1m36: Sending request for user-authentication service.
idwsit1m36: Service accepted: ssh-userauth.
idwsit1m36: Trying empty user-authentication request.
idwsit1m36: Authentication methods that can continue: publickey,gssapi-with-mic,password.
idwsit1m36: Next method to try is publickey.
idwsit1m36: Next method to try is password.
idwsit1m36: Trying password authentication.
idwsit1m36: Will not query passphrase in batch mode.
idwsit1m36: Authentication methods that can continue: publickey,gssapi-with-mic,password.
idwsit1m36: Next method to try is publickey.
idwsit1m36: Next method to try is password.
idwsit1m36: Trying password authentication.
idwsit1m36: Will not query passphrase in batch mode.
idwsit1m36: Authentication methods that can continue: publickey,gssapi-with-mic,password.
idwsit1m36: Next method to try is publickey.
idwsit1m36: Next method to try is password.
idwsit1m36: Trying password authentication.
idwsit1m36: Will not query passphrase in batch mode.
idwsit1m36: Authentication methods that can continue: .
Permission denied at //pkgs/linux/intel/perl/5.8.0/lib/site_perl/5.8.0/Net/SFTP.pm line 62
Please help me to solve this.
Thanks,
Prasanna

Replies are listed 'Best First'.
Re: SFTP Issue
by zentara (Cardinal) on Jul 15, 2008 at 16:41 UTC
    See if you at least can connect.
    #!/usr/bin/perl -w use strict; use Net::SFTP; # Net::SFTP does no error reporting my $sftp = undef; eval{ $sftp = Net::SFTP->new("hostnumber", user=>"me", password=>"mypass", ); }; if ($@) { print "Sftp connection failed:\n $@\n"; } if (! $sftp) { print "I can't connect!\n"; }else{ print "SUCCESS!\n"; }
    If you can connect, it is likely you get permission denied because the file you seek is not in the directory that you think you are in. Try the fullpathname to the file.

    If you can't connect, try Net::SSH2. See A little demo for Net::SSH2 for how to sftp thru it.


    I'm not really a human, but I play one on earth CandyGram for Mongo
      Hi Zentara ,
      I tried the code , i am still getting errors , please find the error below
      Sftp connection failed:
      Permission denied at //pkgs/linux/intel/perl/5.8.0/lib/site_perl/5.8.0/Net/SFTP.pm line 62
      I can't connect!
      Do we need to give the password for sure ? coz when i check in the line 62 of SFTP.pm it corresponds to login using username and password
      Net::ssh2 module is not installed , i need to ask the team to install, i will try that option
      I am able to connect from commandline by using "sftp user@host" withought any password.
      Prasanna
Re: SFTP Issue
by derby (Abbot) on Jul 15, 2008 at 19:31 UTC

    i gave the password as null , since i am not using the password...

    Well ... that's the issue. If you look at line 62 in Net::SFTP that's where the login happens. By passing the password parameter, it's trying to login with a blank password. How are you authenticating via the cmdline? Public key or passphrase?

    -derby
      From command line i am just giving as

      "sftp user@host"

      since while creating the RSA key , i just gave empty for both password and passphrase, But in NET::SFTP , they have mentioned for password as " if you use public key authentication, this argument is unused " so i thought i can give a null

      -prasanna

Re: SFTP Issue
by salva (Canon) on Jul 15, 2008 at 18:35 UTC
Re: SFTP Issue
by Khen1950fx (Canon) on Jul 15, 2008 at 23:40 UTC
    This worked for me:

    #!/usr/bin/perl use strict; use warnings; use Net::SFTP; my $host = 'localhost'; my $remote = '/usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm'; my $local = '/path/to/Desktop'; my %args = ( user => 'someuser', password => 'somepassword', debug => 1 ); my $sftp = Net::SFTP->new($host, %args); $sftp->get($remote, [$local]);
      Khen
      i used your code , still i am getting the same error, the only modification is i gave the password as '' (null).

      use strict; use warnings; use Net::SFTP; my $host = '217.154.215.76'; my $remote = '/usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm'; my $local = '/path/to/Desktop'; my %args = ( user => 'username', password => '', debug => 1 ); my $sftp = Net::SFTP->new($host, %args); #$sftp->get($remote, [$local]);
      the error
      Permission denied at //pkgs/linux/intel/perl/5.8.0/lib/site_perl/5.8.0/Net/SFTP.pm line 62

      In the sftp.pm code, line 62 it corresponds to login , will it not login with null password.

      Prasanna

        I tried it with null password and got permission denied. I tried it without password and got the same thing. It seems to want a password---so try that.