FAQ
I know the answer must be right in front of me, but I just don't see
it...

I wrote a script that looks for files and then sends them to a remote
SFTP server:

<code>
#!/usr/bin/perl -w
use strict;
use Net::SFTP;
use Logit; # this is a homegrown function that takes a filename and
a line
# of text to write to the file.

my $debug = 1;
my $server = "usmlrh03";
my %sftp_args = ( user => 'my_user',
password => 'my_passwd',
debug => $debug);


# Check for the presence of datafiles
my @datafiles = <foo.*>;

if (!@datafiles) {
logit('mylog.log', "No datafiles found");
die "No datafiles";
};

my $sftp = Net::SFTP -> new($server, %sftp_args) or do {
logit('mylog.log', "Can't connect to $server via SFTP");
die "Can't connect to $server via SFTP";
};

my $rc;
for (@datafiles) {

logit('mylog.log', "Putting file: $_");

$rc = $sftp -> put($_);

logit('mylog.log', "Put to $server via SFTP: rc=$rc");
}
exit;
#logit('mylog.log', "@datafiles: sent successfully");
#unlink $dotdone or logit('mylog.log', "Unable to delete $dotdone");
#unlink @datafiles or logit('mylog.log', "Unable to delete @datafiles");


</code>

When I run this I get:

Use of uninitialized value in concatenation (.) at
/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 215.
usmlrh04: sftp: Sent SSH2_FXP_OPEN I:0 P:
Couldn't get handle: No such file or directory at
/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 166.
usmlrh04: sftp: Sent message SSH2_FXP_WRITE I:1 O:0
Couldn't write to remote file: Failure at
/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 261.
usmlrh04: sftp: Sent message T:4 I:2
Couldn't close file: Failure at
/usr/lib/perl5/site_perl/5.6.0/Net/SFTP.pm line 201.
Use of uninitialized value in concatenation (.) at ./my_sftp.pl line 37.

But there definitely is a file in the current directory called foo.csv.
I tried specifying the full path, ie, /home/user/foo.csv, but I got the
same results!

BTW I don't think this should matter, but this is running between two
(old) RH linux boxes.

If anyone can shed any light on this it would be much appreciated!
TIA

richf

Search Discussions

  • Zentara at Nov 11, 2005 at 2:24 pm

    On Thu, 10 Nov 2005 14:04:01 -0500, rfernandez@arrow.com (Richard Fernandez) wrote:

    I know the answer must be right in front of me, but I just don't see
    it...
    SFTP is tricky.
    I wrote a script that looks for files and then sends them to a remote
    SFTP server:
    $rc = $sftp -> put($_);
    If anyone can shed any light on this it would be much appreciated!
    TIA
    From an old tested snippet I have, put takes 2 arguments

    $sftp->put($put_from, "$put_to_dir/$file") || die "Can't open $!\n";



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
  • RICHARD FERNANDEZ at Nov 11, 2005 at 2:34 pm

    If anyone can shed any light on this it would be much appreciated!
    TIA
    From an old tested snippet I have, put takes 2 arguments

    $sftp->put($put_from, "$put_to_dir/$file") || die "Can't open $!\n";



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html





    Thank you zentara. This did it. I had tried supplying a file name for
    the remote side, but I hadn't thought to give it the _full_path_ on the
    remote side. Now I know :)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedNov 10, '05 at 7:04p
activeNov 11, '05 at 2:34p
posts3
users2
websiteperl.org

2 users in discussion

RICHARD FERNANDEZ: 2 posts Zentara: 1 post

People

Translate

site design / logo © 2022 Grokbase