CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Problem with Net::SFTP::Foreign

 



Gus
Novice

Sep 22, 2011, 2:57 AM

Post #1 of 12 (3681 views)
Problem with Net::SFTP::Foreign Can't Post

Hi,

I am using the module Net::SFTP::Foreign (v 1.67) to upload and download files using SFTP. It's working fairly well, but I get an error on the download that I can't get around:

My script:
#----------------
use Net::SFTP::Foreign;

my $host = "hostname";
my %args = (
user => 'user',
password => 'pass',
ssh_cmd => 'plink',
timeout => 30
);

my $indir = 'C:\indir';

my $sftp = Net::SFTP::Foreign->new($host, %args);
$sftp->error and die "unable to connect to remote host: " . $sftp->error;

$sftp->setcwd('/POLLABLE');
print $sftp->cwd . "\n";
$files = $sftp->ls('/POLLABLE');
print "$_->{filename}\n" for @$files;
print "$_->{longname}\n" for @$files;

$sftp->mget('*', $indir) or die "mget failed: " . $sftp->error;

$sftp->disconnect;
#----------------

When running the script in the debugger, this is the output from the print statements:

#----------------
main::(download-sftp-test.pl:22): print "$_->{filename}\n" for @$files;

DB<1>
/POLLABLE/file1
/POLLABLE/file2
/POLLABLE/file3
main::(download-sftp-test.pl:23): print "$_->{longname}\n" for @$files;

DB<1>
-rw-r----- 1 0 0 160 Sep 22 09:00 file1
-rw-r----- 1 0 0 160 Sep 22 09:00 file2
-rw-r----- 1 0 0 160 Sep 22 09:00 file3
#----------------

So there are 3 files of 160 bytes each in the folder. Here comes the output from the mget command:

#----------------
main::(download-sftp-test.pl:35): $sftp->mget('*', $indir) or die "mget filed: " . $sftp->error;
DB<1>
Use of uninitialized value $size in numeric eq (==) at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561.
at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561
Net::SFTP::Foreign::get('Net::SFTP::Foreign=HASH(0xfca6fc)', '/POLLABLE/file1', 'C:\inprod\file1', 'resume', undef, 'numbered', undef,
'block_size', undef, ...) called at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 2693
Net::SFTP::Foreign::mget('Net::SFTP::Foreign=HASH(0xfca6fc)', '*', 'C:\inprod') called at download-sftp-test.pl line 35
Use of uninitialized value $size in numeric gt (>) at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561.
at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561
Net::SFTP::Foreign::get('Net::SFTP::Foreign=HASH(0xfca6fc)', '/POLLABLE/file1', 'C:\inprod\file1', 'resume', undef, 'numbered', undef,
'block_size', undef, ...) called at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 2693
Net::SFTP::Foreign::mget('Net::SFTP::Foreign=HASH(0xfca6fc)', '*', 'C:\inprod') called at download-sftp-test.pl line 35
#----------------

This output is repeated for all 3 files. The files are downloaded correctly, but I would obviously prefer to do it without any error messages. Has anyone seen a similar error?


salva
Novice

Sep 22, 2011, 4:15 AM

Post #2 of 12 (3677 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post


Quote
I am using the module Net::SFTP::Foreign (v 1.67)...


Code
main::(download-sftp-test.pl:35): $sftp->mget('*', $indir) or die "mget filed: " . $sftp->error; 
DB<1>
Use of uninitialized value $size in numeric eq (==) at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561.
at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561



Looking at the module source I can not see how that error can happen at that line when using version 1.67.

Can you run on the debugger...


Code
x $Net::SFTP::Foreign::VERSION


...to ensure that you are actually using that version.

Or have you changed the module yourself? (this may look like a silly question, but it has happened to me on the past, some user changing the module and then filling a bug report because it didn't worked!, so I have to ask :-)

Do you know with software and version is running on the remote side?


(This post was edited by salva on Sep 22, 2011, 4:17 AM)


Gus
Novice

Sep 22, 2011, 6:24 AM

Post #3 of 12 (3674 views)
Re: [salva] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Hi Salva, and thanks a lot for the reply!

DB<1> x $Net::SFTP::Foreign::VERSION
0 1.67

The module is definitely unchanged, installed on ActiveState Perl 5.14 using ppm-shell (install Net-SFTP-Foreign).

I will ask for what OS and sftp server the other side is running, it might take a day or so before I can get a reply though. I'll get back as soon as I can!

Edit: When I've stepped through the program in the debugger, it does output the error message after line 1561 ($n++;), but I guess it checks the while statement on line 1554 to do it. I don't understand why $size is considered uninitialized at that time.


(This post was edited by Gus on Sep 22, 2011, 6:31 AM)


salva
Novice

Sep 22, 2011, 6:48 AM

Post #4 of 12 (3670 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post


Quote
I will ask for what OS and sftp server the other side is running, it might take a day or so before I can get a reply though. I'll get back as soon as I can!


If you connect via telnet or netcat to the ssh port of the remote machine it will tell, for instance:


Code
$ nc localhost 22 
SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1
^C



salva
Novice

Sep 22, 2011, 6:55 AM

Post #5 of 12 (3669 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Could you also set at the beginning of your script...

$Net::SFTP::Foreign::debug = -1;

and then run it and post here the output?

It looks as if the remote side was not including the remote file size on the response to the "stat" request.


Gus
Novice

Sep 26, 2011, 6:52 AM

Post #6 of 12 (3551 views)
Re: [salva] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Hi again, sorry about the late reply. I haven't received a reply yet regarding the software unfortunately. When I try to telnet to the server I get this:

SSH-2.0-GXSSSHD_Comments

When I set the debug = -1 I get a lot of debug output (more than my max allowed buffer size here...). Here is the output from where the $sftp-mget command runs (i have edited paths and filenames in the output manually here, hope that doesn't mess up readability):


Code
main::(download-sftp-test.pl:33):       $sftp->mget('*', $indir) or die "mget fa 
iled: " . $sftp->error;

DB<1> s
Net::SFTP::Foreign::mget(C:/Perl/site/lib/Net/SFTP/Foreign.pm:2645):
2645: @_ >= 2 or croak 'Usage: $sftp->mget($remote, $localdir, %opts)';

DB<1> c 1556
#2880 1317040677.00000 _rel2abs: '.' --> '/POLLABLE'
#2880 1317040677.00000 _rel2abs: '/POLLABLE' --> '/POLLABLE'
#2880 1317040677.00000 _queue_msg: queueing msg len: 31, code:11, id:8 ... [1]
00 00 00 1f 0b 00 00 00 08 00 00 00 16 2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f
50 4f 4c 4c 41 | ............./POLLA
42 4c 45
| BLE
#2880 1317040677.00000 _get_msg: waiting for message... [1]
#2880 1317040677.00000 _get_msg: got it!, len:31, code:102, id:8, status: -
66 00 00 00 08 00 00 00 16 2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f 50 4f 4c 4c
41 42 4c 45 | f......../POLLABLE
#2880 1317040677.00000 opendir: new remote dir '/POLLABLE' open, ri
d:
2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f 50 4f 4c 4c 41 42 4c 45
| /POLLABLE
#2880 1317040677.00000 _queue_msg: queueing msg len: 31, code:12, id:9 ... [1]
00 00 00 1f 0c 00 00 00 09 00 00 00 16 2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f
50 4f 4c 4c 41 | ............./POLLA
42 4c 45
| BLE
#2880 1317040677.00000 _get_msg: waiting for message... [1]
#2880 1317040677.00000 _get_msg: got it!, len:527, code:104, id:9, status: -
68 00 00 00 09 00 00 00 02 00 00 00 69 2f 43 54 45 5f 45 44 2f 41 44 54 30 30 33
37 37 2f 41 42 | h...........i
53 43 49 45 58 54 45 53 54 2f 50 4f 4c 4c 41 42 4c 45 2f 63 6f 6e 74 72 6c 2e 41
42 53 43 49 45 | /POLLABLE/fi
58 54 45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 37 2e 34 31 32 36 34
35 34 5f 36 35 | le1
6c 31 68 33 30 30 36 61 69 66 34 73 36 74 30 30 30 30 74 39 31 38 00 00 00 7a 2d
72 77 2d 72 2d | ...z-rw-r-
2d 2d 2d 2d 20 20 20 31 20 30 20 20 20 20 20 20 20 20 30 20 20 20 20 20 20 20 20
20 20 20 20 20 | ---- 1 0 0
31 36 33 20 53 65 70 20 32 36 20 30 38 3a 35 35 20 63 6f 6e 74 72 6c 2e 41 42 53
43 49 45 58 54 | 163 Sep 26 08:55 fi
45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 37 2e 34 31 32 36 34 35 34
5f 36 35 6c 31 | le1
68 33 30 30 36 61 69 66 34 73 36 74 30 30 30 30 74 39 31 38 00 00 00 0d 00 00 00
00 00 00 00 a3 | ............
00 00 81 a0 4e 80 3e 10 4e 80 3e 10 00 00 00 69 2f 43 54 45 5f 45 44 2f 41 44 54
30 30 33 37 37 | ....N.>.N.>....i
2f 41 42 53 43 49 45 58 54 45 53 54 2f 50 4f 4c 4c 41 42 4c 45 2f 63 6f 6e 74 72
6c 2e 41 42 53 | /POLLABLE/fil
43 49 45 58 54 45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 34 2e 34 31
32 36 34 35 33 | e2
5f 36 35 6c 31 68 31 30 30 36 61 69 66 34 70 31 6c 30 30 30 32 72 6d 33 72 00 00
00 7a 2d 72 77 | ...z-rw
2d 72 2d 2d 2d 2d 2d 20 20 20 31 20 30 20 20 20 20 20 20 20 20 30 20 20 20 20 20
20 20 20 20 20 | -r----- 1 0 0
20 20 20 31 36 33 20 53 65 70 20 32 36 20 30 38 3a 35 35 20 63 6f 6e 74 72 6c 2e
41 42 53 43 49 | 163 Sep 26 08:55 fi
45 58 54 45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 34 2e 34 31 32 36
34 35 33 5f 36 | le2
35 6c 31 68 31 30 30 36 61 69 66 34 70 31 6c 30 30 30 32 72 6d 33 72 00 00 00 0d
00 00 00 00 00 | .........
00 00 a3 00 00 81 a0 4e 80 3e 0d 4e 80 3e 0d
| .......N.>.N.>.
#2880 1317040677.00000 _queue_msg: queueing msg len: 31, code:12, id:10 ... [1]
00 00 00 1f 0c 00 00 00 0a 00 00 00 16 2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f
50 4f 4c 4c 41 | ............./POLLA
42 4c 45
| BLE
#2880 1317040677.00000 _get_msg: waiting for message... [1]
#2880 1317040677.00000 _get_msg: got it!, len:54, code:101, id:10, status: 1
65 00 00 00 0a 00 00 00 01 00 00 00 25 54 68 65 72 65 20 61 72 65 20 6e 6f 20 6d
6f 72 65 20 66 | e...........%There are no more f
69 6c 65 73 20 66 6f 72 20 74 68 69 73 20 75 73 65 72 00 00 00 00
| iles for this user....
#2880 1317040677.00000 _set_status: _set_status code: 1, str: There are no more
files for this user
#2880 1317040677.00000 _set_error: _set_err code: 29, str: Couldn't read directo
ry '/POLLABLE': There are no more files for this user
#2880 1317040677.00000 _queue_msg: queueing msg len: 31, code:4, id:11 ... [1]
00 00 00 1f 04 00 00 00 0b 00 00 00 16 2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f
50 4f 4c 4c 41 | ............./POLLA
42 4c 45
| BLE
#2880 1317040677.00000 _get_msg: waiting for message... [1]
#2880 1317040678.00000 _get_msg: got it!, len:40, code:101, id:11, status: 0
65 00 00 00 0b 00 00 00 00 00 00 00 17 54 68 65 20 6f 70 65 72 61 74 69 6f 6e 20
63 6f 6d 70 6c | e............The operation compl
65 74 65 64 00 00 00 00
| eted....
#2880 1317040678.00000 _close: closing file handle, return: 1, rid:
2f 41 44 54 30 30 33 37 37 2f 2e 2f 2e 2f 50 4f 4c 4c 41 42 4c 45
| /POLLABLE
#2880 1317040678.00000 DESTROY: Net::SFTP::Foreign::DirHandle=GLOB(0x11f754c)->D
ESTROY called (sftp: )
#2880 1317040678.00000 _rel2abs: '/POLLABLE/file1' --> '/000 _rel2abs: '/POLLABLE/file1' --> '/POLLABLE/file1
s6t0000t918'
#2880 1317040678.00000 _queue_msg: queueing msg len: 114, code:17, id:12 ... [1]

00 00 00 72 11 00 00 00 0c 00 00 00 69 2f 43 54 45 5f 45 44 2f 41 44 54 30 30 33
37 37 2f 41 42 | ...r........i/PO
53 43 49 45 58 54 45 53 54 2f 50 4f 4c 4c 41 42 4c 45 2f 63 6f 6e 74 72 6c 2e 41
42 53 43 49 45 | LLABLE/fil
58 54 45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 37 2e 34 31 32 36 34
35 34 5f 36 35 | e2
6c 31 68 33 30 30 36 61 69 66 34 73 36 74 30 30 30 30 74 39 31 38
|
#2880 1317040678.00000 _get_msg: waiting for message... [1]
#2880 1317040678.00000 _get_msg: got it!, len:21, code:105, id:12, status: -
69 00 00 00 0c 00 00 00 0c 00 00 81 80 4e 80 6f fd 4e 80 6f fd
| i............N.o.N.o.
#2880 1317040678.00000 _rel2abs: '/POLLABLE/file2' --> '/POLLABLE/file2'
#2880 1317040678.00000 _queue_msg: queueing msg len: 122, code:3, id:13 ... [1]
00 00 00 7a 03 00 00 00 0d 00 00 00 69 2f 43 54 45 5f 45 44 2f 41 44 54 30 30 33
37 37 2f 41 42 | ...z........i/POL
53 43 49 45 58 54 45 53 54 2f 50 4f 4c 4c 41 42 4c 45 2f 63 6f 6e 74 72 6c 2e 41
42 53 43 49 45 | LABLE/fil
58 54 45 53 54 5f 32 30 31 31 30 39 32 36 5f 30 33 35 35 33 37 2e 34 31 32 36 34
35 34 5f 36 35 | e2
6c 31 68 33 30 30 36 61 69 66 34 73 36 74 30 30 30 30 74 39 31 38 00 00 00 01 00
00 00 00 |
#2880 1317040678.00000 _get_msg: waiting for message... [1]
#2880 1317040678.00000 _get_msg: got it!, len:33, code:102, id:13, status: -
66 00 00 00 0d 00 00 00 18 36 35 6c 31 68 33 30 30 36 61 69 66 34 73 36 74 30 30
30 30 74 39 31 | f........65l1h3006aif4s6t0000t91
38
| 8
#2880 1317040678.00000 open: new remote file '/POLLA
BLE/file2' open, r
id:
36 35 6c 31 68 33 30 30 36 61 69 66 34 73 36 74 30 30 30 30 74 39 31 38
| Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1556):
1556: my $id = $sftp->_queue_new_msg(SSH2_FXP_READ, str=> $rfi
d,
1557: int64 => $askoff, int32 =
> $block_size);

DB<2> n
#2880 1317042033.00000 _queue_msg: queueing msg len: 45, code:5, id:14 ... [1]
00 00 00 2d 05 00 00 00 0e 00 00 00 18 36 35 6c 31 68 33 30 30 36 61 69 66 34 73
36 74 30 30 30 | ...-.........65l1h3006aif4s6t000
30 74 39 31 38 00 00 00 00 00 00 00 00 00 00 80 00
| 0t918............
Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1558):
1558: push @msgid, $id;

DB<2>
Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1559):
1559: push @askoff, $askoff;

DB<2>
Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1560):
1560: $askoff += $block_size;

DB<2>
Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1561):
1561: $n++;

DB<2>
Use of uninitialized value $size in numeric eq (==) at C:/Perl/site/lib/Net/SFTP
/Foreign.pm line 1561.
at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561
Net::SFTP::Foreign::get('Net::SFTP::Foreign=HASH(0xfca464)', '/POLLABLE/
file2', 'C:\inprod\file1', 'resume', undef, 'numbered', undef,
'block_size', undef, ...) called at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 2
693
Net::SFTP::Foreign::mget('Net::SFTP::Foreign=HASH(0xfca464)', '*', 'C:\i
nprod') called at download-sftp-test.pl li
ne 33
Use of uninitialized value $size in numeric gt (>) at C:/Perl/site/lib/Net/SFTP/
Foreign.pm line 1561.
at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 1561
Net::SFTP::Foreign::get('Net::SFTP::Foreign=HASH(0xfca464)', '/POLLABLE/
file2', 'C:\inprod\file2', 'resume', undef, 'numbered', undef,
'block_size', undef, ...) called at C:/Perl/site/lib/Net/SFTP/Foreign.pm line 2
693
Net::SFTP::Foreign::mget('Net::SFTP::Foreign=HASH(0xfca464)', '*', 'C:\i
nprod') called at download-sftp-test.pl li
ne 33
Net::SFTP::Foreign::get(C:/Perl/site/lib/Net/SFTP/Foreign.pm:1564):
1564: my $eid = shift @msgid;

DB<2>



salva
Novice

Sep 27, 2011, 12:58 AM

Post #7 of 12 (3529 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post


In Reply To

Code
#2880 1317040678.00000 _get_msg: got it!, len:21, code:105, id:12, status: -  
69 00 00 00 0c 00 00 00 0c 00 00 81 80 4e 80 6f fd 4e 80 6f fd



This is the ATTRS response to the STAT request performed by Net::SFTP::Foreign::get and it includes the permissions and the timestamps of the file but not its size.

It's funny because, the size was actually included on the ATTRS embedded inside the response to the READDIR request sent from mget.

Anyway, just another crappy SFTP server, I will include a workaround for this problem in the next release of the module (that I would try to release today).


Gus
Novice

Sep 27, 2011, 1:00 AM

Post #8 of 12 (3528 views)
Re: [salva] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Wow, you are amazing! Thank you so much for your help. I will download the new version as soon as it is available.


salva
Novice

Sep 27, 2011, 5:30 AM

Post #9 of 12 (3512 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post

https://metacpan.org/release/SALVA/Net-SFTP-Foreign-1.68_05


Gus
Novice

Sep 27, 2011, 6:13 AM

Post #10 of 12 (3508 views)
Re: [salva] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Thank you so much! A question on installing it:

Trying to install through cpan or ActiveState ppm still shows module version 1.67. Can I unzip the module from your link and just drop the new SFTP folder with contents to C:\Perl\site\lib\Net\SFTP replacing the previous version?


salva
Novice

Sep 27, 2011, 6:17 AM

Post #11 of 12 (3506 views)
Re: [Gus] Problem with Net::SFTP::Foreign [In reply to] Can't Post

Yes, that will do.


Gus
Novice

Sep 27, 2011, 6:21 AM

Post #12 of 12 (3501 views)
Re: [salva] Problem with Net::SFTP::Foreign [In reply to] Can't Post

I tested it now, and it worked perfectly. You made my day, thank you again!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives