Login failing with SFTP

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.

Login failing with SFTP

Postby tonyc » Tue Aug 13, 2013 10:21 am

Hello, I'm new to using secure FTP via PHP, so thank you for this excellent script to make the whole process simpler. However I can't seem to get it working. I can log into the sFTP server fine using WinSCP, however when I try to use phpseclib it always returns Login Failed. I have the following code:
Code: Select all
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include 'Net/SFTP.php';

$sftp = new NET_SFTP('***');
if(!$sftp->login('***', '***')) {
   exit('Login Failed');

echo $sftp->pwd();

It always hits Login Failed, and that is all there is on the screen. Can anyone tell me how I can debug this? I've tried define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX); and then echo $sftp->getSFTPLog(); just above the exit line, however that produces nothing as well.

I have also asked about this on Stack Overflow, if anyone wishes to view that post you can here.
Last edited by tonyc on Tue Aug 13, 2013 12:45 pm, edited 1 time in total.
Posts: 5
Joined: Tue Aug 13, 2013 10:15 am

Re: Login failing with SFTP

Postby TerraFrost » Tue Aug 13, 2013 12:45 pm

Try this:

Code: Select all
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include 'Net/SFTP.php';


$sftp = new NET_SFTP('nft.sftp.tesco.biz');
if(!$sftp->login('uat_1003601', 'Cap34Han4U')) {
   echo $sftp->getLog();
   exit('Login Failed');

echo $sftp->pwd();

So I'm doing the define() right after the include and I'm doing SSH2 logging instead of SFTP logging. The reason for that is that true login errors happen at the SSH layer - not at the SFTP layer. It's possible there could be an SFTP issue, as well, but with the SSH2 logs I'll be able to see that as well (the SSH2 logs contain the SFTP traffic).
Legendary Guard
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Login failing with SFTP

Postby tonyc » Tue Aug 13, 2013 12:49 pm

Thank you for the help, I'm getting:

Code: Select all
No common algorithms.

00000000  53:53:48:2d:32:2e:30:2d:4a:53:43:41:50:45:0d:0a  SSH-2.0-JSCAPE..

00000000  53:53:48:2d:32:2e:30:2d:70:68:70:73:65:63:6c:69  SSH-2.0-phpsecli
00000010  62:5f:30:2e:33:20:28:6d:63:72:79:70:74:2c:20:62  b_0.3 (mcrypt, b
00000020  63:6d:61:74:68:29:0d:0a                          cmath)..

<- NET_SSH2_MSG_KEXINIT (since last: 0.0226, network: 0.0065s)
00000000  29:91:19:28:32:77:01:f9:2c:c1:9c:51:44:a8:24:e5  )..(2w..,..QD.$.
00000010  00:00:00:1a:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ....diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:00:00  an-group1-sha1..
00000030  00:07:73:73:68:2d:72:73:61:00:00:00:15:62:6c:6f  ..ssh-rsa....blo
00000040  77:66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d:63  wfish-cbc,3des-c
00000050  62:63:00:00:00:15:62:6c:6f:77:66:69:73:68:2d:63  bc....blowfish-c
00000060  62:63:2c:33:64:65:73:2d:63:62:63:00:00:00:12:68  bc,3des-cbc....h
00000070  6d:61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64  mac-sha1,hmac-md
00000080  35:00:00:00:12:68:6d:61:63:2d:73:68:61:31:2c:68  5....hmac-sha1,h
00000090  6d:61:63:2d:6d:64:35:00:00:00:04:7a:6c:69:62:00  mac-md5....zlib.
000000a0  00:00:04:7a:6c:69:62:00:00:00:00:00:00:00:00:00  ...zlib.........
000000b0  00:00:00:00                                      ....

-> NET_SSH2_MSG_KEXINIT (since last: 0.0005, network: 0s)
00000000  e5:5f:41:e0:49:0c:c6:97:99:b1:e9:31:f9:1d:62:05  ._A.I......1..b.
00000010  00:00:00:36:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ...6diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:2c:64  an-group1-sha1,d
00000030  69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72  iffie-hellman-gr
00000040  6f:75:70:31:34:2d:73:68:61:31:00:00:00:0f:73:73  oup14-sha1....ss
00000050  68:2d:72:73:61:2c:73:73:68:2d:64:73:73:00:00:00  h-rsa,ssh-dss...
00000060  f6:61:72:63:66:6f:75:72:32:35:36:2c:61:72:63:66  .arcfour256,arcf
00000070  6f:75:72:31:32:38:2c:61:72:63:66:6f:75:72:2c:61  our128,arcfour,a
00000080  65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39:32  es128-ctr,aes192
00000090  2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72:2c  -ctr,aes256-ctr,
000000a0  74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c:74  twofish128-ctr,t
000000b0  77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74:77  wofish192-ctr,tw
000000c0  6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65:73  ofish256-ctr,aes
000000d0  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
000000e0  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74:77  bc,aes256-cbc,tw
000000f0  6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77:6f  ofish128-cbc,two
00000100  66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f:66  fish192-cbc,twof
00000110  69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  ish256-cbc,twofi
00000120  73:68:2d:63:62:63:2c:62:6c:6f:77:66:69:73:68:2d  sh-cbc,blowfish-
00000130  63:74:72:2c:62:6c:6f:77:66:69:73:68:2d:63:62:63  ctr,blowfish-cbc
00000140  2c:33:64:65:73:2d:63:74:72:2c:33:64:65:73:2d:63  ,3des-ctr,3des-c
00000150  62:63:2c:6e:6f:6e:65:00:00:00:f6:61:72:63:66:6f  bc,none....arcfo
00000160  75:72:32:35:36:2c:61:72:63:66:6f:75:72:31:32:38  ur256,arcfour128
00000170  2c:61:72:63:66:6f:75:72:2c:61:65:73:31:32:38:2d  ,arcfour,aes128-
00000180  63:74:72:2c:61:65:73:31:39:32:2d:63:74:72:2c:61  ctr,aes192-ctr,a
00000190  65:73:32:35:36:2d:63:74:72:2c:74:77:6f:66:69:73  es256-ctr,twofis
000001a0  68:31:32:38:2d:63:74:72:2c:74:77:6f:66:69:73:68  h128-ctr,twofish
000001b0  31:39:32:2d:63:74:72:2c:74:77:6f:66:69:73:68:32  192-ctr,twofish2
000001c0  35:36:2d:63:74:72:2c:61:65:73:31:32:38:2d:63:62  56-ctr,aes128-cb
000001d0  63:2c:61:65:73:31:39:32:2d:63:62:63:2c:61:65:73  c,aes192-cbc,aes
000001e0  32:35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:31  256-cbc,twofish1
000001f0  32:38:2d:63:62:63:2c:74:77:6f:66:69:73:68:31:39  28-cbc,twofish19
00000200  32:2d:63:62:63:2c:74:77:6f:66:69:73:68:32:35:36  2-cbc,twofish256
00000210  2d:63:62:63:2c:74:77:6f:66:69:73:68:2d:63:62:63  -cbc,twofish-cbc
00000220  2c:62:6c:6f:77:66:69:73:68:2d:63:74:72:2c:62:6c  ,blowfish-ctr,bl
00000230  6f:77:66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d  owfish-cbc,3des-
00000240  63:74:72:2c:33:64:65:73:2d:63:62:63:2c:6e:6f:6e  ctr,3des-cbc,non
00000250  65:00:00:00:30:68:6d:61:63:2d:73:68:61:31:2d:39  e...0hmac-sha1-9
00000260  36:2c:68:6d:61:63:2d:73:68:61:31:2c:68:6d:61:63  6,hmac-sha1,hmac
00000270  2d:6d:64:35:2d:39:36:2c:68:6d:61:63:2d:6d:64:35  -md5-96,hmac-md5
00000280  2c:6e:6f:6e:65:00:00:00:30:68:6d:61:63:2d:73:68  ,none...0hmac-sh
00000290  61:31:2d:39:36:2c:68:6d:61:63:2d:73:68:61:31:2c  a1-96,hmac-sha1,
000002a0  68:6d:61:63:2d:6d:64:35:2d:39:36:2c:68:6d:61:63  hmac-md5-96,hmac
000002b0  2d:6d:64:35:2c:6e:6f:6e:65:00:00:00:04:6e:6f:6e  -md5,none....non
000002c0  65:00:00:00:04:6e:6f:6e:65:00:00:00:00:00:00:00  e....none.......
000002d0  00:00:00:00:00:00                                ......

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.007, network: 0s)
00000000  00:00:00:80:5a:c6:96:6c:22:22:23:3b:4d:9b:30:e6  ....Z..l""#;M.0.
00000010  0b:f9:f9:91:92:e2:8f:56:e1:ff:f1:00:de:86:e4:26  .......V.......&
00000020  aa:73:ef:f4:a2:cf:7b:bc:d5:3c:55:c5:f1:16:20:10  .s....{...U... .
00000030  3e:42:3a:89:0b:47:4b:1c:b2:ff:d0:3a:92:57:f8:cd  >B:..GK....:.W..
00000040  36:a1:e5:a9:26:6f:ca:2c:0c:0e:cc:7e:27:2f:35:9d  6...&o.,...~'/5.
00000050  a8:a0:1a:bf:d7:35:9e:91:4a:6a:2e:4a:13:76:3c:69  .....5..Jj.J.v.i
00000060  65:a4:71:24:56:bf:97:0c:de:ae:10:75:d3:93:55:d3  e.q$V......u..U.
00000070  d7:c3:1a:1d:ee:58:5e:84:c6:c0:67:19:5b:4c:17:b7  .....X^...g.[L..
00000080  c7:00:d5:cd                                      ....

<- NET_SSH2_MSG_DISCONNECT (since last: 0.0002, network: 0.0002s)
00000000  00:00:00:03:00:00:00:15:4e:6f:20:63:6f:6d:6d:6f  ........No commo
00000010  6e:20:61:6c:67:6f:72:69:74:68:6d:73:2e:00:00:00  n algorithms....
00000020  02:65:6e                                         .en

Login Failed

What would cause the key exchange to fail?

Edit: Would this be a zlib requirement? The same as viewtopic.php?f=46&t=67751#p221481?
Last edited by tonyc on Tue Aug 13, 2013 2:36 pm, edited 1 time in total.
Posts: 5
Joined: Tue Aug 13, 2013 10:15 am

Re: Login failing with SFTP

Postby TerraFrost » Tue Aug 13, 2013 2:00 pm

It'd make it a little more readable if you did <pre> lol.

Anyway it's saying "no common algorithms". Since it's hard to read without the <pre> tags I'm not 100% sure but it does look like zlib is probably the issue.
Legendary Guard
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Login failing with SFTP

Postby tonyc » Tue Aug 13, 2013 2:37 pm

Lol, not used the <pre> tag before. I've done that now and updated the code above.
Posts: 5
Joined: Tue Aug 13, 2013 10:15 am

Re: Login failing with SFTP

Postby TerraFrost » Tue Aug 13, 2013 3:02 pm

Yah - it's because phpseclib doesn't support compression.

Technically, that means that your SSH server is not implementing SSH correctly. Quoting the RFC:

Code: Select all
   The following compression methods are currently defined:

      none     REQUIRED        no compression
      zlib     OPTIONAL        ZLIB (LZ77) compression

none is REQUIRED and if your SSH server isn't supporting it... well it's off spec...
Legendary Guard
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Login failing with SFTP

Postby tonyc » Tue Aug 13, 2013 3:09 pm

Unfortunately it's not my server or I'd just change it... that is a pain in the ass. Ah well, thank you very much for you help with this. I will have to attempt an alternative method for connecting securely to the server.
Posts: 5
Joined: Tue Aug 13, 2013 10:15 am

Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 3 guests