SFTP - Error when sending file
Hello,
I have a problem when I want to send a file through SFTP. This is the following.
[Symfony\Component\Debug\Exception\ContextErrorException] Warning: file_put_contents(): Unable to open ssh2.sftp://Resource id #568/${path_remote} on remote host
Here is my code :
$configuration = new Configuration('url'); $authentication = new Password('username', 'password'); $session = new Session($configuration, $authentication); $sftp = $session->getSftp(); $sftp->send("local_file", "remote_file");
Error is on the last line.
Can you help me please ?
Thanks.
Anthony
Does the file get transferred? Is it the only warning you get?
Hello !
Thank you for your answer. Unfortunately, my file does not get transferred.
Have you maybe another idea ? :-)
It would help to know if SCP works at all beforehand. Could you try to transfer the file using scp like described here?
http://www.hypexr.org/linux_scp_help.php
Yes I can transfer file with SCP command.
@anthonyherve Whats your PHP Version?
I can confirm this bug, using this version of PHP:
$ php -v
PHP 5.6.5-1+deb.sury.org~trusty+1 (cli) (built: Jan 26 2015 11:42:37)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
Here is my version :
PHP 5.5.21 (cli) (built: Jan 21 2015 14:44:22)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
I reran the last travis builds, and the functional tests there worked: https://travis-ci.org/Herzult/php-ssh/builds/49846322
Event against our PHP Versions 5.5.21 and 5.6.5.
I honestly dont know whats wrong here :weary:
Probably related bug - https://bugs.php.net/bug.php?id=64169.
Same bug. PHP 5.5.9 : https://i.imgur.com/k6HPsvU.jpg
Same on PHP 7.0.19 (cli) (built: May 13 2017 00:54:47) ( NTS )
@h4cc @Herzult it is connected with https://bugs.php.net/bug.php?id=73597
Solution (intval):
namespace Ssh;
class Sftp extends Subsystem
{
.
.
.
.
public function getUrl($filename)
{
return sprintf('ssh2.sftp://%s/%s', intval($this->getResource()), $filename);
}
}
Thanks for that fix @marcint1990, that worked for me.
I found I was also getting the remote fully-qualified path wrong. A bare filename would not work for me, I had to add /home/user/ as well.
Is someone raising a patch/PR for this?
I'm not sure why @Herzult abandoned the repo, but fixed version can be found among forks (for example, https://github.com/GinoPane/php-ssh v1.1.2)