Asked  1 Year ago    Answers:  5   Viewed   8 times

Trying to get a simple SFTP file transfer working in PHP with phpseclib. Here's the code:

<?php
    ini_set('display_errors', '1');
    error_reporting(E_ALL);
    include_once ('Net/SFTP.php');
    define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);

    $sftp = new Net_SFTP("foo.example.com");
    if (!$sftp->login("username", "password")) {
        echo($sftp->getLog());
        exit('Login Failed');
    }
    echo($sftp->getLog());
    $sftp->get("remotefile.txt", "localfile.txt");
?>

It works perfectly everywhere but on the Windows/Apache machine that it needs to. On Windows it dies at the incoming NET_SSH2_MSG_SERVICE_REQUEST. No errors are returned, but login fails. Everyone is running Apache 2.2 and PHP 5.3. Here's the log:

<br />
<b>Notice</b>:  Invalid HMAC in <b>[...]NetSSH2.php</b> on line <b>3037</b><br />
<br />
<b>Notice</b>:  Connection closed by server in <b>[...]NetSSH2.php</b> on line <b>2015</b><br />
<-
00000000  53:53:48:2d:32:2e:30:2d:31:2e:38:32:20:73:73:68  SSH-2.0-1.82 ssh
00000010  6c:69:62:3a:20:73:73:68:6c:69:62:53:72:53:73:68  lib: sshlibSrSsh
00000020  53:65:72:76:65:72:20:31:2e:30:30:0d:0a           Server 1.00..

->
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:6f:70:65:6e:73:73:6c:2c:20  b_0.3 (openssl, 
00000020  62:63:6d:61:74:68:29:0d:0a                       bcmath)..

<- NET_SSH2_MSG_KEXINIT (since last: 1.545, network: 0.084s)
00000000  de:e7:02:d1:3c:35:5e:4d:71:88:af:d3:2b:66:fe:c4  .....5^Mq...+f..
00000010  00:00:00:59:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ...Ydiffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:34:2d:73:68:61:31:2c  an-group14-sha1,
00000030  64:69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67  diffie-hellman-g
00000040  72:6f:75:70:2d:65:78:63:68:61:6e:67:65:2d:73:68  roup-exchange-sh
00000050  61:31:2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d:61  a1,diffie-hellma
00000060  6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:00:00:00  n-group1-sha1...
00000070  07:73:73:68:2d:72:73:61:00:00:00:69:61:65:73:32  .ssh-rsa...iaes2
00000080  35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:32:35  56-cbc,twofish25
00000090  36:2d:63:62:63:2c:74:77:6f:66:69:73:68:2d:63:62  6-cbc,twofish-cb
000000a0  63:2c:61:65:73:31:32:38:2d:63:62:63:2c:74:77:6f  c,aes128-cbc,two
000000b0  66:69:73:68:31:32:38:2d:63:62:63:2c:62:6c:6f:77  fish128-cbc,blow
000000c0  66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d:63:62  fish-cbc,3des-cb
000000d0  63:2c:61:72:63:66:6f:75:72:2c:63:61:73:74:31:32  c,arcfour,cast12
000000e0  38:2d:63:62:63:00:00:00:69:61:65:73:32:35:36:2d  8-cbc...iaes256-
000000f0  63:62:63:2c:74:77:6f:66:69:73:68:32:35:36:2d:63  cbc,twofish256-c
00000100  62:63:2c:74:77:6f:66:69:73:68:2d:63:62:63:2c:61  bc,twofish-cbc,a
00000110  65:73:31:32:38:2d:63:62:63:2c:74:77:6f:66:69:73  es128-cbc,twofis
00000120  68:31:32:38:2d:63:62:63:2c:62:6c:6f:77:66:69:73  h128-cbc,blowfis
00000130  68:2d:63:62:63:2c:33:64:65:73:2d:63:62:63:2c:61  h-cbc,3des-cbc,a
00000140  72:63:66:6f:75:72:2c:63:61:73:74:31:32:38:2d:63  rcfour,cast128-c
00000150  62:63:00:00:00:2b:68:6d:61:63:2d:73:68:61:31:2c  bc...+hmac-sha1,
00000160  68:6d:61:63:2d:6d:64:35:2c:68:6d:61:63:2d:73:68  hmac-md5,hmac-sh
00000170  61:31:2d:39:36:2c:68:6d:61:63:2d:6d:64:35:2d:39  a1-96,hmac-md5-9
00000180  36:00:00:00:2b:68:6d:61:63:2d:73:68:61:31:2c:68  6...+hmac-sha1,h
00000190  6d:61:63:2d:6d:64:35:2c:68:6d:61:63:2d:73:68:61  mac-md5,hmac-sha
000001a0  31:2d:39:36:2c:68:6d:61:63:2d:6d:64:35:2d:39:36  1-96,hmac-md5-96
000001b0  00:00:00:09:7a:6c:69:62:2c:6e:6f:6e:65:00:00:00  ....zlib,none...
000001c0  09:7a:6c:69:62:2c:6e:6f:6e:65:00:00:00:00:00:00  .zlib,none......
000001d0  00:00:00:00:00:00:00                             .......

-> NET_SSH2_MSG_KEXINIT (since last: 0.001, network: 0s)
00000000  80:76:aa:0f:87:22:c1:df:73:35:eb:39:41:b2:c1:0c  .v..."..s5.9A...
00000010  00:00:00:7e: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: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:2c:64:69:66:66:69  oup14-sha1,diffi
00000050  65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:2d  e-hellman-group-
00000060  65:78:63:68:61:6e:67:65:2d:73:68:61:31:2c:64:69  exchange-sha1,di
00000070  66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f  ffie-hellman-gro
00000080  75:70:2d:65:78:63:68:61:6e:67:65:2d:73:68:61:32  up-exchange-sha2
00000090  35:36:00:00:00:0f:73:73:68:2d:72:73:61:2c:73:73  56....ssh-rsa,ss
000000a0  68:2d:64:73:73:00:00:00:e9:61:72:63:66:6f:75:72  h-dss....arcfour
000000b0  32:35:36:2c:61:72:63:66:6f:75:72:31:32:38:2c:61  256,arcfour128,a
000000c0  65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39:32  es128-ctr,aes192
000000d0  2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72:2c  -ctr,aes256-ctr,
000000e0  74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c:74  twofish128-ctr,t
000000f0  77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74:77  wofish192-ctr,tw
00000100  6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65:73  ofish256-ctr,aes
00000110  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
00000120  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74:77  bc,aes256-cbc,tw
00000130  6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77:6f  ofish128-cbc,two
00000140  66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f:66  fish192-cbc,twof
00000150  69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  ish256-cbc,twofi
00000160  73:68:2d:63:62:63:2c:62:6c:6f:77:66:69:73:68:2d  sh-cbc,blowfish-
00000170  63:74:72:2c:62:6c:6f:77:66:69:73:68:2d:63:62:63  ctr,blowfish-cbc
00000180  2c:33:64:65:73:2d:63:74:72:2c:33:64:65:73:2d:63  ,3des-ctr,3des-c
00000190  62:63:00:00:00:e9:61:72:63:66:6f:75:72:32:35:36  bc....arcfour256
000001a0  2c:61:72:63:66:6f:75:72:31:32:38:2c:61:65:73:31  ,arcfour128,aes1
000001b0  32:38:2d:63:74:72:2c:61:65:73:31:39:32:2d:63:74  28-ctr,aes192-ct
000001c0  72:2c:61:65:73:32:35:36:2d:63:74:72:2c:74:77:6f  r,aes256-ctr,two
000001d0  66:69:73:68:31:32:38:2d:63:74:72:2c:74:77:6f:66  fish128-ctr,twof
000001e0  69:73:68:31:39:32:2d:63:74:72:2c:74:77:6f:66:69  ish192-ctr,twofi
000001f0  73:68:32:35:36:2d:63:74:72:2c:61:65:73:31:32:38  sh256-ctr,aes128
00000200  2d:63:62:63:2c:61:65:73:31:39:32:2d:63:62:63:2c  -cbc,aes192-cbc,
00000210  61:65:73:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  aes256-cbc,twofi
00000220  73:68:31:32:38:2d:63:62:63:2c:74:77:6f:66:69:73  sh128-cbc,twofis
00000230  68:31:39:32:2d:63:62:63:2c:74:77:6f:66:69:73:68  h192-cbc,twofish
00000240  32:35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:2d  256-cbc,twofish-
00000250  63:62:63:2c:62:6c:6f:77:66:69:73:68:2d:63:74:72  cbc,blowfish-ctr
00000260  2c:62:6c:6f:77:66:69:73:68:2d:63:62:63:2c:33:64  ,blowfish-cbc,3d
00000270  65:73:2d:63:74:72:2c:33:64:65:73:2d:63:62:63:00  es-ctr,3des-cbc.
00000280  00:00:39:68:6d:61:63:2d:73:68:61:32:2d:32:35:36  ..9hmac-sha2-256
00000290  2c:68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d  ,hmac-sha1-96,hm
000002a0  61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64:35  ac-sha1,hmac-md5
000002b0  2d:39:36:2c:68:6d:61:63:2d:6d:64:35:00:00:00:39  -96,hmac-md5...9
000002c0  68:6d:61:63:2d:73:68:61:32:2d:32:35:36:2c:68:6d  hmac-sha2-256,hm
000002d0  61:63:2d:73:68:61:31:2d:39:36:2c:68:6d:61:63:2d  ac-sha1-96,hmac-
000002e0  73:68:61:31:2c:68:6d:61:63:2d:6d:64:35:2d:39:36  sha1,hmac-md5-96
000002f0  2c:68:6d:61:63:2d:6d:64:35:00:00:00:04:6e:6f:6e  ,hmac-md5....non
00000300  65:00:00:00:04:6e:6f:6e:65:00:00:00:00:00:00:00  e....none.......
00000310  00:00:00:00:00:00                                ......

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.012, network: 0s)
00000000  00:00:00:80:69:2e:eb:cd:aa:4f:eb:b2:0f:ab:3a:5c  ....i....O....:
00000010  ad:43:bb:51:7e:7e:c1:90:58:13:98:aa:3d:e3:d2:7b  .C.Q~~..X...=..{
00000020  b7:2b:ab:b0:ec:18:9a:d1:87:c0:99:26:82:ef:8e:a3  .+.........&....
00000030  18:81:69:91:2a:8f:ed:73:4a:29:c0:2e:85:b2:50:d2  ..i.*..sJ)....P.
00000040  f8:8b:6f:a7:60:8e:d4:7b:97:e9:da:a3:80:9d:93:7a  ..o.`..{.......z
00000050  30:a5:aa:31:bc:83:33:f4:2d:8c:18:c6:4d:bc:58:f4  0..1..3.-...M.X.
00000060  5f:0c:03:57:b6:8d:72:cd:a0:cd:1a:56:55:fd:82:d6  _..W..r....VU...
00000070  5f:21:e8:77:34:65:79:eb:87:03:80:a9:c4:04:a2:6d  _!.w4ey........m
00000080  a1:b6:e8:11                                      ....

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 0.09, network: 0.09s)
00000000  00:00:00:95:00:00:00:07:73:73:68:2d:72:73:61:00  ........ssh-rsa.
00000010  00:00:01:11:00:00:00:81:00:bc:a7:d7:98:5f:d5:ce  ............._..
00000020  a4:15:2f:84:52:bf:2e:70:19:e7:85:08:24:21:e9:02  ../.R..p....$!..
00000030  29:3e:a6:6e:f8:c4:f8:6d:6f:db:a6:06:53:20:e2:02  )>.n...mo...S ..
00000040  4d:db:75:16:a3:66:1d:4f:da:1d:63:d0:46:45:b8:f4  M.u..f.O..c.FE..
00000050  5a:37:bd:e4:c1:25:6c:42:3c:44:c2:8b:47:37:3d:27  Z7...%lB.D..G7='
00000060  1a:f0:45:1e:83:fb:5c:c7:b9:36:35:5b:0d:f1:70:b5  ..E.....65[..p.
00000070  c0:0d:18:c6:39:e9:5a:29:61:8f:3e:47:5e:f1:c8:35  ....9.Z)a.>G^..5
00000080  18:09:c9:ab:08:f3:a6:35:f2:61:3e:93:d4:f8:65:0f  .......5.a>...e.
00000090  8e:83:04:28:e8:fa:f5:95:53:00:00:00:80:51:79:eb  ...(....S....Qy.
000000a0  65:26:79:1d:6c:d5:ac:09:09:81:32:1b:c9:99:d4:89  e&y.l.....2.....
000000b0  9a:59:92:63:d5:5e:e9:d2:d7:fa:ef:a1:7c:33:20:0c  .Y.c.^......|3 .
000000c0  89:0f:09:67:1f:0f:0f:2a:47:39:d7:e5:67:a5:e4:eb  ...g...*G9..g...
000000d0  12:e0:b9:6e:0f:e4:17:56:bc:ba:49:ef:f3:a1:ba:cc  ...n...V..I.....
000000e0  a3:2c:57:26:46:c9:62:0e:8c:ca:87:e5:65:10:86:e0  .,W&F.b.....e...
000000f0  fd:80:be:ce:18:a0:d3:3b:33:73:b0:07:0f:de:de:72  .......;3s.....r
00000100  33:0b:30:62:d5:b3:c8:89:b2:dd:01:0b:d8:d9:53:92  3.0b..........S.
00000110  17:3f:e2:02:6d:15:ce:1b:ab:c7:4f:8d:44:00:00:00  .?..m.....O.D...
00000120  8f:00:00:00:07:73:73:68:2d:72:73:61:00:00:00:80  .....ssh-rsa....
00000130  4f:fb:0e:44:b3:1a:b0:9c:68:6e:e4:db:39:d1:a2:bd  O..D....hn..9...
00000140  c0:54:ef:7e:50:ef:60:98:33:d4:cd:e3:b1:92:6f:6d  .T.~P.`.3.....om
00000150  39:64:78:86:01:f0:ba:20:e9:ae:a6:78:b4:d4:d4:a1  9dx.... ...x....
00000160  e6:96:7a:a6:1e:9e:04:60:04:9c:97:81:0b:a4:56:63  ..z....`......Vc
00000170  16:b4:d8:77:d0:4b:c6:d1:6c:f1:7b:df:65:8f:5d:e1  ...w.K..l.{.e.].
00000180  9e:af:6d:c1:a8:57:d6:42:7d:38:3f:96:3f:4c:3c:78  ..m..W.B}8?.?L.x
00000190  a0:fb:be:7e:51:1f:b7:b0:e6:35:79:31:46:d4:dd:42  ...~Q....5y1F..B
000001a0  c6:aa:fa:7f:09:0c:10:a5:cf:26:5f:16:0c:dd:8f:46  .........&_....F

-> NET_SSH2_MSG_NEWKEYS (since last: 0.011, network: 0s)


<- NET_SSH2_MSG_NEWKEYS (since last: 0.001, network: 0s)


-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.003, network: 0s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

Login Failed

For comparison, here's a log from a successful login on a different server:

<-
00000000  53:53:48:2d:32:2e:30:2d:31:2e:38:32:20:73:73:68  SSH-2.0-1.82 ssh
00000010  6c:69:62:3a:20:73:73:68:6c:69:62:53:72:53:73:68  lib: sshlibSrSsh
00000020  53:65:72:76:65:72:20:31:2e:30:30:0d:0a           Server 1.00..

->
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:6f:70:65:6e:73:73:6c:2c:20  b_0.3 (openssl, 
00000020  62:63:6d:61:74:68:29:0d:0a                       bcmath)..

<- NET_SSH2_MSG_KEXINIT (since last: 1.0692, network: 0.0864s)
00000000  18:37:a9:f6:4e:9e:59:ee:e2:dc:9d:f3:0d:20:03:d3  .7..N.Y...... ..
00000010  00:00:00:59:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ...Ydiffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:34:2d:73:68:61:31:2c  an-group14-sha1,
00000030  64:69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67  diffie-hellman-g
00000040  72:6f:75:70:2d:65:78:63:68:61:6e:67:65:2d:73:68  roup-exchange-sh
00000050  61:31:2c:64:69:66:66:69:65:2d:68:65:6c:6c:6d:61  a1,diffie-hellma
00000060  6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:00:00:00  n-group1-sha1...
00000070  07:73:73:68:2d:72:73:61:00:00:00:69:61:65:73:32  .ssh-rsa...iaes2
00000080  35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:32:35  56-cbc,twofish25
00000090  36:2d:63:62:63:2c:74:77:6f:66:69:73:68:2d:63:62  6-cbc,twofish-cb
000000a0  63:2c:61:65:73:31:32:38:2d:63:62:63:2c:74:77:6f  c,aes128-cbc,two
000000b0  66:69:73:68:31:32:38:2d:63:62:63:2c:62:6c:6f:77  fish128-cbc,blow
000000c0  66:69:73:68:2d:63:62:63:2c:33:64:65:73:2d:63:62  fish-cbc,3des-cb
000000d0  63:2c:61:72:63:66:6f:75:72:2c:63:61:73:74:31:32  c,arcfour,cast12
000000e0  38:2d:63:62:63:00:00:00:69:61:65:73:32:35:36:2d  8-cbc...iaes256-
000000f0  63:62:63:2c:74:77:6f:66:69:73:68:32:35:36:2d:63  cbc,twofish256-c
00000100  62:63:2c:74:77:6f:66:69:73:68:2d:63:62:63:2c:61  bc,twofish-cbc,a
00000110  65:73:31:32:38:2d:63:62:63:2c:74:77:6f:66:69:73  es128-cbc,twofis
00000120  68:31:32:38:2d:63:62:63:2c:62:6c:6f:77:66:69:73  h128-cbc,blowfis
00000130  68:2d:63:62:63:2c:33:64:65:73:2d:63:62:63:2c:61  h-cbc,3des-cbc,a
00000140  72:63:66:6f:75:72:2c:63:61:73:74:31:32:38:2d:63  rcfour,cast128-c
00000150  62:63:00:00:00:2b:68:6d:61:63:2d:73:68:61:31:2c  bc...+hmac-sha1,
00000160  68:6d:61:63:2d:6d:64:35:2c:68:6d:61:63:2d:73:68  hmac-md5,hmac-sh
00000170  61:31:2d:39:36:2c:68:6d:61:63:2d:6d:64:35:2d:39  a1-96,hmac-md5-9
00000180  36:00:00:00:2b:68:6d:61:63:2d:73:68:61:31:2c:68  6...+hmac-sha1,h
00000190  6d:61:63:2d:6d:64:35:2c:68:6d:61:63:2d:73:68:61  mac-md5,hmac-sha
000001a0  31:2d:39:36:2c:68:6d:61:63:2d:6d:64:35:2d:39:36  1-96,hmac-md5-96
000001b0  00:00:00:09:7a:6c:69:62:2c:6e:6f:6e:65:00:00:00  ....zlib,none...
000001c0  09:7a:6c:69:62:2c:6e:6f:6e:65:00:00:00:00:00:00  .zlib,none......
000001d0  00:00:00:00:00:00:00                             .......

-> NET_SSH2_MSG_KEXINIT (since last: 0.0009, network: 0s)
00000000  ba:0c:4e:f7:26:8e:51:80:3f:0a:10:78:b3:ba:ca:f4  ..N.&.Q.?..x....
00000010  00:00:00:7e: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: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:2c:64:69:66:66:69  oup14-sha1,diffi
00000050  65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f:75:70:2d  e-hellman-group-
00000060  65:78:63:68:61:6e:67:65:2d:73:68:61:31:2c:64:69  exchange-sha1,di
00000070  66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72:6f  ffie-hellman-gro
00000080  75:70:2d:65:78:63:68:61:6e:67:65:2d:73:68:61:32  up-exchange-sha2
00000090  35:36:00:00:00:0f:73:73:68:2d:72:73:61:2c:73:73  56....ssh-rsa,ss
000000a0  68:2d:64:73:73:00:00:00:e9:61:72:63:66:6f:75:72  h-dss....arcfour
000000b0  32:35:36:2c:61:72:63:66:6f:75:72:31:32:38:2c:61  256,arcfour128,a
000000c0  65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39:32  es128-ctr,aes192
000000d0  2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72:2c  -ctr,aes256-ctr,
000000e0  74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c:74  twofish128-ctr,t
000000f0  77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74:77  wofish192-ctr,tw
00000100  6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65:73  ofish256-ctr,aes
00000110  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
00000120  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74:77  bc,aes256-cbc,tw
00000130  6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77:6f  ofish128-cbc,two
00000140  66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f:66  fish192-cbc,twof
00000150  69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  ish256-cbc,twofi
00000160  73:68:2d:63:62:63:2c:62:6c:6f:77:66:69:73:68:2d  sh-cbc,blowfish-
00000170  63:74:72:2c:62:6c:6f:77:66:69:73:68:2d:63:62:63  ctr,blowfish-cbc
00000180  2c:33:64:65:73:2d:63:74:72:2c:33:64:65:73:2d:63  ,3des-ctr,3des-c
00000190  62:63:00:00:00:e9:61:72:63:66:6f:75:72:32:35:36  bc....arcfour256
000001a0  2c:61:72:63:66:6f:75:72:31:32:38:2c:61:65:73:31  ,arcfour128,aes1
000001b0  32:38:2d:63:74:72:2c:61:65:73:31:39:32:2d:63:74  28-ctr,aes192-ct
000001c0  72:2c:61:65:73:32:35:36:2d:63:74:72:2c:74:77:6f  r,aes256-ctr,two
000001d0  66:69:73:68:31:32:38:2d:63:74:72:2c:74:77:6f:66  fish128-ctr,twof
000001e0  69:73:68:31:39:32:2d:63:74:72:2c:74:77:6f:66:69  ish192-ctr,twofi
000001f0  73:68:32:35:36:2d:63:74:72:2c:61:65:73:31:32:38  sh256-ctr,aes128
00000200  2d:63:62:63:2c:61:65:73:31:39:32:2d:63:62:63:2c  -cbc,aes192-cbc,
00000210  61:65:73:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  aes256-cbc,twofi
00000220  73:68:31:32:38:2d:63:62:63:2c:74:77:6f:66:69:73  sh128-cbc,twofis
00000230  68:31:39:32:2d:63:62:63:2c:74:77:6f:66:69:73:68  h192-cbc,twofish
00000240  32:35:36:2d:63:62:63:2c:74:77:6f:66:69:73:68:2d  256-cbc,twofish-
00000250  63:62:63:2c:62:6c:6f:77:66:69:73:68:2d:63:74:72  cbc,blowfish-ctr
00000260  2c:62:6c:6f:77:66:69:73:68:2d:63:62:63:2c:33:64  ,blowfish-cbc,3d
00000270  65:73:2d:63:74:72:2c:33:64:65:73:2d:63:62:63:00  es-ctr,3des-cbc.
00000280  00:00:39:68:6d:61:63:2d:73:68:61:32:2d:32:35:36  ..9hmac-sha2-256
00000290  2c:68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d  ,hmac-sha1-96,hm
000002a0  61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64:35  ac-sha1,hmac-md5
000002b0  2d:39:36:2c:68:6d:61:63:2d:6d:64:35:00:00:00:39  -96,hmac-md5...9
000002c0  68:6d:61:63:2d:73:68:61:32:2d:32:35:36:2c:68:6d  hmac-sha2-256,hm
000002d0  61:63:2d:73:68:61:31:2d:39:36:2c:68:6d:61:63:2d  ac-sha1-96,hmac-
000002e0  73:68:61:31:2c:68:6d:61:63:2d:6d:64:35:2d:39:36  sha1,hmac-md5-96
000002f0  2c:68:6d:61:63:2d:6d:64:35:00:00:00:04:6e:6f:6e  ,hmac-md5....non
00000300  65:00:00:00:04:6e:6f:6e:65:00:00:00:00:00:00:00  e....none.......
00000310  00:00:00:00:00:00                                ......

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.0151, network: 0s)
00000000  00:00:00:80:04:bc:13:ad:9c:ab:d4:d5:16:8a:2a:77  ..............*w
00000010  fd:e0:e3:95:90:cb:1e:e3:e2:f7:72:f5:db:31:d2:ca  ..........r..1..
00000020  22:97:38:d4:c0:5c:3f:db:de:99:dc:a7:76:e0:94:ad  ".8..?.....v...
00000030  c7:6e:94:2d:0d:b8:ee:77:41:75:35:03:bf:9a:9f:1f  .n.-...wAu5.....
00000040  ae:96:21:39:59:fc:fb:63:da:c7:50:81:80:76:34:e3  ..!9Y..c..P..v4.
00000050  5d:cf:9b:f6:a3:de:bb:c0:16:19:04:3e:81:99:24:92  ]..........>..$.
00000060  4c:d7:50:a4:6c:5f:b7:d4:cb:de:f0:d5:36:ba:4a:7b  L.P.l_......6.J{
00000070  19:60:64:48:bc:06:6a:33:fc:e0:a3:fa:5a:6c:c5:0b  .`dH..j3....Zl..
00000080  5b:bf:61:28                                      [.a(

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 0.4882, network: 0.4881s)
00000000  00:00:00:95:00:00:00:07:73:73:68:2d:72:73:61:00  ........ssh-rsa.
00000010  00:00:01:11:00:00:00:81:00:bc:a7:d7:98:5f:d5:ce  ............._..
00000020  a4:15:2f:84:52:bf:2e:70:19:e7:85:08:24:21:e9:02  ../.R..p....$!..
00000030  29:3e:a6:6e:f8:c4:f8:6d:6f:db:a6:06:53:20:e2:02  )>.n...mo...S ..
00000040  4d:db:75:16:a3:66:1d:4f:da:1d:63:d0:46:45:b8:f4  M.u..f.O..c.FE..
00000050  5a:37:bd:e4:c1:25:6c:42:3c:44:c2:8b:47:37:3d:27  Z7...%lB.D..G7='
00000060  1a:f0:45:1e:83:fb:5c:c7:b9:36:35:5b:0d:f1:70:b5  ..E.....65[..p.
00000070  c0:0d:18:c6:39:e9:5a:29:61:8f:3e:47:5e:f1:c8:35  ....9.Z)a.>G^..5
00000080  18:09:c9:ab:08:f3:a6:35:f2:61:3e:93:d4:f8:65:0f  .......5.a>...e.
00000090  8e:83:04:28:e8:fa:f5:95:53:00:00:00:81:00:ef:17  ...(....S.......
000000a0  88:86:6f:8f:99:f3:c9:f6:da:8a:cb:30:65:99:8b:c9  ..o........0e...
000000b0  ca:44:7b:d4:86:55:a5:a5:5d:bd:0d:c8:9e:b7:cb:89  .D{..U..].......
000000c0  fd:89:d4:53:7b:80:61:20:8a:59:3b:89:9a:7b:8b:31  ...S{.a .Y;..{.1
000000d0  9a:e7:c2:7f:ba:38:54:96:5b:92:30:cb:a0:c3:b1:2c  .....8T.[.0....,
000000e0  68:b4:e7:2e:af:ba:64:73:08:ce:b4:f9:5e:e4:36:07  h.....ds....^.6.
000000f0  d4:34:2a:00:2d:1b:4c:76:c8:67:3d:3a:23:b7:29:a5  .4*.-.Lv.g=:#.).
00000100  e3:45:9a:c2:b1:ed:c9:85:cc:05:15:cb:9d:fc:9b:9e  .E..............
00000110  3b:5d:e4:bc:0a:d5:8d:0f:dc:24:d8:e3:ed:0d:00:00  ;].......$......
00000120  00:8f:00:00:00:07:73:73:68:2d:72:73:61:00:00:00  ......ssh-rsa...
00000130  80:5e:a3:72:63:cd:76:8b:8c:6c:49:01:30:1b:b1:aa  .^.rc.v..lI.0...
00000140  19:02:93:53:1e:d0:47:ed:8c:c5:02:2e:60:94:5b:eb  ...S..G.....`.[.
00000150  60:3e:b2:63:44:bc:d7:6b:bc:4e:af:2d:d9:88:4c:3e  `>.cD..k.N.-..L>
00000160  d7:97:fc:c8:2e:8b:27:15:42:bb:a2:3e:b7:8a:8c:64  ......'.B..>...d
00000170  7e:ec:8b:75:dc:64:d2:67:dd:b3:e2:76:a0:56:b9:ab  ~..u.d.g...v.V..
00000180  05:3b:2b:73:e0:65:a0:a6:c3:92:e2:a3:db:46:11:eb  .;+s.e.......F..
00000190  ca:40:ff:4e:1f:cd:d8:5a:b9:c4:39:f9:81:d2:40:75  .@.N...Z..9...@u
000001a0  a3:8b:e4:61:d1:bd:0a:2a:3e:b7:42:88:58:e1:04:fa  ...a...*>.B.X...
000001b0  29                                               )

-> NET_SSH2_MSG_NEWKEYS (since last: 0.0131, network: 0s)


<- NET_SSH2_MSG_NEWKEYS (since last: 0.0001, network: 0s)


-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0031, network: 0s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

<- NET_SSH2_MSG_SERVICE_ACCEPT (since last: 0.7004, network: 0.7003s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0002, network: 0s)
00000000  00:00:00:08:75:73:65:72:6e:61:6d:65:00:00:00:0e  ....username....
00000010  73:73:68:2d:63:6f:6e:6e:65:63:74:69:6f:6e:00:00  ssh-connection..
00000020  00:08:70:61:73:73:77:6f:72:64:00:00:00:00:08:70  ..password.....p
00000030  61:73:73:77:6f:72:64                             assword

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 2.9883, network: 2.9882s)


-> NET_SSH2_MSG_CHANNEL_OPEN (since last: 0.0002, network: 0s)
00000000  00:00:00:07:73:65:73:73:69:6f:6e:00:00:01:00:7f  ....session.....
00000010  ff:ff:ff:00:00:40:00                             .....@.

<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.0984, network: 0.0001s)
00000000  00:00:01:00:00:00:00:00:00:00:40:00:00:00:8c:00  ..........@.....

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0003, network: 0s)
00000000  00:00:00:00:00:00:00:09:73:75:62:73:79:73:74:65  ........subsyste
00000010  6d:01:00:00:00:04:73:66:74:70                    m.....sftp

<- NET_SSH2_MSG_CHANNEL_SUCCESS (since last: 0.0853, network: 0.0001s)
00000000  00:00:01:00                                      ....

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0003, network: 0s)
00000000  00:00:00:00:00:00:00:09:00:00:00:05:01:00:00:00  ................
00000010  03                                               .

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.089, network: 0.0889s)
00000000  00:00:01:00:00:00:00:09:00:00:00:05:02:00:00:00  ................
00000010  03                                               .

-> NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0001s)
00000000  00:00:00:00:00:00:00:0e:00:00:00:0a:10:00:00:00  ................
00000010  01:00:00:00:01:2e                                ......

<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0901, network: 0.09s)
00000000  00:00:01:00:00:00:00:37:00:00:00:33:68:00:00:00  .......7...3h...
00000010  01:00:00:00:01:00:00:00:01:2f:00:00:00:01:2f:00  ........./..../.
00000020  00:00:0f:00:00:00:00:00:00:10:00:00:00:00:00:00  ................
00000030  00:00:00:00:00:41:c0:55:b1:54:db:55:b1:54:db     .....A.U.T.U.T.

 Answers

3

The problem was in one of the algorithms it was trying to use. With both aes128-cbc and aes256-cbc available on the Windows server, it choked. Commenting them out allows the connection to complete without errors:

In Net/SSH2.php in _key_exchange():

//'aes128-cbc',     // RECOMMENDED       AES with a 128-bit key
'aes192-cbc',     // OPTIONAL          AES with a 192-bit key
//'aes256-cbc',     // OPTIONAL          AES in CBC mode, with a 256-bit key
Saturday, May 29, 2021
 
redrom
 
4

You have to retrieve a list of all files in the remote directory using Net_SFTP::nlist.

Then you iterate the list, finding a file name that matches your requirements.

Then you download the selected file using Net_SFTP::get.

include("Net/SFTP.php");

$sftp = new Net_SFTP("host");

if (!$sftp->login("username", "password"))
{
    die("Cannot connect");
}

$path = "/remote/path";
$list = $sftp->nlist($path);

if ($list === false)
{
    die("Error listing directory ".$path);
}

$prefix = "prefix";
$matches = preg_grep("/^$prefix.*/i", $list);
if (count($matches) != 1)
{
    die("No file or more than one file matches the pattern: ".implode(",", $matches));
}

$matches = array_values($matches);
$filename = $matches[0];
$filepath = $path."/".$filename;
if (!$sftp->get($filepath, $filename))
{
    die("Error downloading file ".$filepath);
}
Thursday, April 1, 2021
 
3

You are right about why you're getting the StaleObjectStateException.

If what you're looking for is pessimistic locking (allowing only one transaction access to the data at any given time), then you can use the domain class lock() method:

class TestService {
    static transactional = true

    TesteSync incrementa() {
        TesteSync t = TesteSync.lock(1)
        t.contador++
        return t.save()
    }
}

You can learn more about Grails pessimistic locking here.

PS: Grails services are transactional by default. But in my example I explicitly made the service transactional to call something to your attention: The lock is released by Grails automatically when the transaction commits. I also removed the flush because the data gets flushed when the transaction commits. If you were doing this from a controller method that's not explicitly set to @Transactional, then you would need the flush.

TIP: When you query by ID you can do this...

SomeDomainClass.get(1)

...instead of this...

SomeDomainClass.findById(1)
Saturday, August 21, 2021
 
flygaio
 
3

phpseclib uses mcrypt if it's available and it's own pure PHP implementation otherwise. If you do phpinfo() do you see mcrypt installed?

Also, SSH2 supports a multitude of encryption algorithms and some are faster than others. It could be that the client you're comparing phpseclib against is simply using a faster algorithm than phpseclib has implemented.

Finally, what version of phpseclib are you using? The latest is 0.3.7.

Tuesday, August 31, 2021
 
3

Your resource path starts with a / and is therefore an absolute path. If you want the resource path to be relative you have to omit the first /.

From the Javadoc of Class.getResource(String name):

If the name begins with a '/' ('u002f'), then the absolute name of the resource is the portion of the name following the '/'.

Otherwise, the absolute name is of the following form: modified_package_name/name where the modified_package_name is the package name of this object with '/' substituted for '.' ('u002e').

A relative path is relative to the path of the class returned by getClass().

An example:

package org.example;

public class MyClass {
    public void foo() {
        getClass().getResource("tut01/shaders/vertex_shader.glsl");
    }
}

Let's assume the compiler writes the compiled class file to /home/my-project/bin/org/example/MyClass.class.

getClass().getResource("tut01/shaders/vertex_shader.glsl") would then look for the file in /home/my-project/bin/org/example/tut01/shaders/vertex_shader.glsl.

Sunday, December 19, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :