#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    11

    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.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,263
    Rep Power
    1810
    $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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    11
    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.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,263
    Rep Power
    1810
    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);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    11
    thanks a lot, now it works well !
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

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

IMN logo majestic logo threadwatch logo seochat tools logo