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

I have write some script that run Net::SFTP to transfer a file from my machine to the another machine...Here is the code...

==================================
#!/usr/bin/perl use Net::SFTP; #use strict; #use warnings; $host = $ARGV[0]; $anonyuser = $ARGV[1]; if($ARGV[1] eq "-a") { $username = "anonymous"; $password = "-anonymous@"; } else { print("\nHost\/IP: "); $host = <STDIN>; chomp ($host); print("\nUsername: "); $username = <STDIN>; chomp ($username); print("\nPassword: "); $password = <STDIN>; chomp ($password); } print("Connecting to $host...\n"); $ssh = Net::SFTP -> new($host) or die "Couldn't connect to $host\n"; print("Connected!\n"); print("\nSFC>"); $ssh->login($username, $password) or die "Could not log in .\n"; rep: $command = <STDIN>; chomp ($command); unless ("$command" eq "bye") { @listing = $ssh->$command; for($i=0;$i<@listing;$i++) { print "$listing[$i]\n"; + } print("SFC>"); #goto rep; }
=========

It look ok...But at the end i got this message

Permission denied at /usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 3 +9

I don't know what's going on....i hope someone can help me

Janitored by davido: Added formatting and code tags.

Replies are listed 'Best First'.
Re: Net::SFTP...permission denied
by tachyon (Chancellor) on Sep 13, 2004 at 07:05 UTC

    I don't know what's going on....i hope someone can help me

    Did you consider looking at line 39 of SFTP.pm to see where the error came from? This process is called UTSL amongst other things. Of course before resorting to RTFS you would typically RTFM which you will find at Net::SFTP. When you consult the documentation you may note that the module author has tried to help you..... For a start you could try turning on debugging:

    $ssh = Net::SFTP->new($host, debug => 1 ) or die "Blech\n";

    which would further explain your 'Permission Denied' error. But if you do either of RTFM/RTFS you will note that you need to pass the USERNAME and PASSWORD to the new() constructor. This should work:

    $ssh = Net::SFTP->new($host, user => $user, pass => $pass, debug => 1 +) or die "Blech\n";

    cheers

    tachyon

      I've the same problem with a script that run under debian 3.0 for the last years. now, with SuSE 9.2 und perl 5.8.5 I get Permission denied at /usr/lib/perl5/site_perl/5.8.5/Net/SFTP.pm line 37 and this line or 5 lines there look like: sub init { my $sftp = shift; my %param = @_; $sftp->{debug} = delete $param{debug}; $param{ssh_args} ||= []; $sftp->{_msg_id} = 0; my $ssh = Net::SSH::Perl->new($sftp->{host}, protocol => 2, debug => 1, @{ $param{ssh_args} }); AAA $ssh->login($param{user}, $param{password}); $sftp->{ssh} = $ssh; my $channel = $sftp->_open_channel; $sftp->{channel} = $channel; $sftp->do_init; $sftp; } Line 37 is where you find "AAA" in the beginning of the line. I don't know much about perl but I've to get it working.... Please help me. Thanks LeeLooB