SFTP GET results in an error "Bad address"

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

SFTP GET results in an error "Bad address"

Postby robinek » Wed Jul 24, 2013 7:59 am

Hi,

i need to use phpseclib for get files by SFTP, but I get result "Bad address".
I've PHP 5.3 and latest version of phpseclib from composer ("phpseclib/phpseclib": "0.3.*@dev")
I try to get file backup.rsc from host 192.168.1.1 to local directory.
Determine the file size is ok, but when I try to download a file I get an error "NET_SFTP_STATUS_FAILURE: Bad address".
Something wrong in my script ?

Here is my script with each command log

Code: Select all
$sftp = new Net_SFTP('192.168.1.1');
if (!$sftp->login('username', 'password')) {
   exit('Login Failed');
}

-> NET_SFTP_INIT (0.0002s)
00000000 00:00:00:03 ....

<- NET_SFTP_VERSION (0.0046s)
00000000 00:00:00:03 ....

-> NET_SFTP_REALPATH (0.0004s)
00000000 00:00:00:01:2e .....

<- NET_SFTP_NAME (0.0134s)
00000000 00:00:00:01:00:00:00:01:2f:00:00:00:38:64:72:77 ......../...8drw
00000010 78:72:2d:78:72:2d:78:20:20:20:31:20:30:20:20:20 xr-xr-x 1 0
00000020 20:20:20:20:20:30:20:20:20:20:20:20:20:20:20:20 0
00000030 20:20:20:35:31:32:20:4a:61:6e:20:30:31:20:20:31 512 Jan 01 1
00000040 39:37:30:20:2f:00:00:00:0f:00:00:00:00:00:00:02 970 /...........
00000050 00:00:00:00:00:00:00:00:00:00:00:41:ed:00:00:00 ...........A....
00000060 23:00:00:00:23 #...#

Code: Select all
$size=$sftp->size('backup.rsc');

-> NET_SFTP_STAT (0.0004s)
00000000 00:00:00:0b:2f:62:61:63:6b:75:70:2e:72:73:63 ..../backup.rsc

<- NET_SFTP_ATTRS (0.0119s)
00000000 00:00:00:0f:00:00:00:00:00:00:07:31:00:00:00:00 ...........1....
00000010 00:00:00:00:00:00:81:80:51:ef:84:99:51:ef:84:99 ........Q...Q...

Code: Select all
echo "File size: ".$size;

File size: 1841

Code: Select all
$sftp->get('backup.rsc', '/var/backup/192.168.1.1/backup.rsc');

-> NET_SFTP_OPEN (0.0007s)
00000000 00:00:00:0b:2f:62:61:63:6b:75:70:2e:72:73:63:00 ..../backup.rsc.
00000010 00:00:01:00:00:00:00 .......

<- NET_SFTP_HANDLE (0.0024s)
00000000 00:00:00:14:68:61:6e:64:6c:65:5f:31:00:00:00:00 ....handle_1....
00000010 00:00:00:00:00:00:00:00 ........

-> NET_SFTP_READ (0.0005s)
00000000 00:00:00:14:68:61:6e:64:6c:65:5f:31:00:00:00:00 ....handle_1....
00000010 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 ................
00000020 00:10:00:00 ....

<- NET_SFTP_STATUS (0.002s)
00000000 00:00:00:04:00:00:00:0b:42:61:64:20:61:64:64:72 ........Bad addr
00000010 65:73:73:00:00:00:00 ess....

-> NET_SFTP_CLOSE (0.0007s)
00000000 00:00:00:14:68:61:6e:64:6c:65:5f:31:00:00:00:00 ....handle_1....
00000010 00:00:00:00:00:00:00:00 ........

<- NET_SFTP_STATUS (0.0028s)
00000000 00:00:00:00:00:00:00:00:00:00:00:00 ............

Code: Select all
print_r($sftp->->getSFTPErrors());

Array
(
[0] => NET_SFTP_STATUS_FAILURE: Bad address
)
robinek
Traveler
 
Posts: 4
Joined: Wed Jul 24, 2013 7:33 am

Re: SFTP GET results in an error "Bad address"

Postby TerraFrost » Wed Jul 24, 2013 4:05 pm

That's weird.

Can you get at the file with any other SFTP client? In particular, can you use PuTTY's psftp and if so could you get me logs from it?

You can enable logging by going to PuTTY->Session->Logging and checking the "SSH packets" radio button. Then save the session and then go to psftp and load the session by doing something like "psftp -load sessionName" or something.

Thanks!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: SFTP GET results in an error "Bad address"

Postby robinek » Wed Jul 24, 2013 5:10 pm

Putty PSFTP works and the file downloads fine.
Putty session log is in attachment.
I also tried your Net_SCP and it's also working, but I need a functional SFTP too.

Thanks
Attachments
putty.txt
Putty log
(67.73 KiB) Downloaded 143 times
robinek
Traveler
 
Posts: 4
Joined: Wed Jul 24, 2013 7:33 am

Re: SFTP GET results in an error "Bad address"

Postby TerraFrost » Fri Jul 26, 2013 5:51 am

Sorry for the delay.

Anyway, in SFTP.php find this line:

Code: Select all
        $size = (1 << 20) < $length || $length < 0 ? 1 << 20 : $length;

And try replacing it with this:

Code: Select all
        $size = 0x8000 < $length || $length < 0 ? 0x8000 : $length;

Don't know for sure that that'll fix the problem but it's the best guess I got atm.

Thanks!
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: SFTP GET results in an error "Bad address"

Postby robinek » Fri Jul 26, 2013 9:19 am

Great, it's working ! :)
Is it a global problem and will You fix it in the next version or is it just my (device) problem and I need to fix each new version myself?

Thanks a lot!
robinek
Traveler
 
Posts: 4
Joined: Wed Jul 24, 2013 7:33 am

Re: SFTP GET results in an error "Bad address"

Postby TerraFrost » Fri Jul 26, 2013 3:24 pm

It's not really a global error - more of just a finicky SFTP server lol. None-the-less, I've made a commit that should change the size when the server identifies itself as SSH-2.0-ROSSSH (as yours is):

https://github.com/phpseclib/phpseclib/ ... 4cdd22d9d0
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: SFTP GET results in an error "Bad address"

Postby robinek » Mon Jul 29, 2013 9:14 am

Thank you !
I hope that it is same on every Mikrotik firmware release :)
robinek
Traveler
 
Posts: 4
Joined: Wed Jul 24, 2013 7:33 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 2 guests

cron