2

I'm trying to use the SFTP connection in PHP application, SFTP connection throws invalid size error, please anyone help me out to solve this.

$sftp = Yii::app()->phpseclib->createSFTP($ftp_server,8822);

if (!$sftp->login($ftp_username, $ftp_password)) {  // Login failed

}  

Error throws as:

2018/01/30 11:42:11 [error] [php] Invalid size (D:\xampp\htdocs\viahttps\protected\extensions\phpseclib\classes\Net\SSH2.php:2607)
    Stack trace:
    #0 D:\xampp\htdocs\viahttps\protected\extensions\phpseclib\classes\Net\SSH2.php(1720): Net_SFTP->_login_helper()
    #1 unknown(0): Net_SFTP->_login()
    #2 D:\xampp\htdocs\viahttps\protected\extensions\phpseclib\classes\Net\SFTP.php(405): call_user_func_array()
US-1234
  • 1,519
  • 4
  • 24
  • 61
  • 1
    What version of phpseclib is that? + Can you connect to the SSH server using any standalone SFTP client from the same machine where you run your PHP code? – Martin Prikryl Jan 30 '18 at 13:17
  • Can you post the SSH logs? You can get them by doing `define('NET_SSH2_LOGGING', 2);` at the top and then `echo $ssh->getLog();` after the login attempt fails. This will enable us to see a number of things, including what ciphers are being used. – neubert Jan 30 '18 at 14:26

1 Answers1

2

The wrapper you are using is for 0.3.6 whereas this issue of invalid size has been there since 0.3.5 and was fixed in 0.3.7 after releasing when people bumped into the same error while upgrading from 0.3.6. See this ISSUE

Currently phpseclib is on version 2.0.1 you might need to look if the wrapper you are using has the latest phpseclib source files or otherwise.

  1. You need to look for some other extension doing the same thing.

  2. Override the phpseclib files used by the wrapper from this URL and copy all files and folders inside the phpseclib folder and paste them in the protected/extensions/phpseclib/classes and replace duplicate or override if the file exists.

Note: there might be a possibility that the wrapper throws an error or exception somewhere as the version has a huge gap drastically so this might involve fixing the bugs that appear after upgrading the source classes, or maybe not.

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
  • phpseclib 0.3.6 Yii extension used, i could not find any new wrapper for Yii, Please give me an idea – US-1234 Feb 01 '18 at 11:57
  • have you tried to update the source files as i told you ? @US-1234 – Muhammad Omer Aslam Feb 02 '18 at 00:07
  • you mean new phpseclib ? – US-1234 Feb 02 '18 at 04:08
  • yes the new files i checked them they are the same number as in the old wrapper try replacing and using them i am confident it will work if the previous version worked with the wrapper @US-1234 – Muhammad Omer Aslam Feb 02 '18 at 07:30
  • i am getting Class not found error, class phpseclib/Net/SSH2.php in SFTP.php file, please provide an idea to use phpseclib wihout wrapper in YII ? – US-1234 Feb 05 '18 at 12:46
  • sorry i just watched your message , and the reason it is not working is that the latest version uses namespaces and have a different approach to load the files plus it uses composer you might have to spend some time to configure that old wrapper, if you want to use it without wrapper there are lots of examples [**`HERE`**](http://phpseclib.sourceforge.net/ssh/auth.html#rsakey) and above all before going for any other solution [**`HERE`**](https://github.com/mincms1/yii-1.1/blob/master/protected/vendor/phpseclib) is a `yii1` setup configured with the `seclib` hope it helps you out. @US-1234 – Muhammad Omer Aslam Feb 05 '18 at 22:45
  • @US-1234 did the `yii1` configured project setup with `phpseclib` helped? if yes do leave a message so i should add the info to the answer so it might help others facing the problem, as you selected it as correct answer after some time and whatever in this answer or comments helped you out do specify – Muhammad Omer Aslam Feb 19 '18 at 23:15
  • 1
    I have used the latest version of Phpseclib library – US-1234 Feb 20 '18 at 03:54