0

I have uploaded my local code on new server. Server is Centos 7 with PHP 5.6.31 and PHP 5.5.28.

I have installed ssh2 connect library on both of my php versions. I am trying to connect to other server using below code,

if (!function_exists("ssh2_connect"))
    die('Function ssh2_connect not found, you cannot use ssh2 here');
if (!$connection = ssh2_connect($schema['conn']['host'], $schema['conn']['port']))
    die('Unable to connect');
if (!ssh2_auth_password($schema['conn']['connection'], $schema['conn']['username'], $schema['conn']['password']))
    die('Unable to authenticate.');
if (!$stream = ssh2_sftp($schema['conn']['connection']))
    die('Unable to create a stream.');
if (!$dir = opendir('ssh2.sftp://'.intval($stream).$remoteDirPath))
    die('Could not open the directory');

My code is working fine till

  if (!$stream = ssh2_sftp($schema['conn']['connection']))
    die('Unable to create a stream.');

After that i am getting "Could not open the directory" error. This code is working fine in my local.

Can anyone help me for the issue? Please let me know if any further information is needed.

Arpi Patel
  • 775
  • 4
  • 10
  • 23
  • What is the value in $remetDirPath? Does it exist? – Ivo P Jul 19 '17 at 13:25
  • Yup Its my remote directory path ex. /home/test/file – Arpi Patel Jul 19 '17 at 13:27
  • including the filename? Or is it the name of the directory? – Ivo P Jul 19 '17 at 14:18
  • Its directory. Not file name. We have many files in this folder to work on. so we are just checking with directory and then dig into for files. – Arpi Patel Jul 20 '17 at 06:41
  • I don't see anything wrong with this then. Maybe try the last remark on https://stackoverflow.com/questions/8840883/how-to-list-files-of-a-directory-in-an-other-server-using-ssh2 about using `ls`. But that's more a work around than a solution on why it is not working – Ivo P Jul 20 '17 at 09:17

0 Answers0