Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP - Error when sending file #42

Open
anthonyherve opened this issue Feb 12, 2015 · 12 comments
Open

SFTP - Error when sending file #42

anthonyherve opened this issue Feb 12, 2015 · 12 comments

Comments

@anthonyherve
Copy link

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

@h4cc
Copy link
Collaborator

h4cc commented Feb 13, 2015

Does the file get transferred?
Is it the only warning you get?

@anthonyherve
Copy link
Author

Hello !

Thank you for your answer.
Unfortunately, my file does not get transferred.

Have you maybe another idea ? :-)

@h4cc
Copy link
Collaborator

h4cc commented Feb 13, 2015

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

@anthonyherve
Copy link
Author

Yes I can transfer file with SCP command.

@h4cc
Copy link
Collaborator

h4cc commented Feb 13, 2015

@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

@anthonyherve
Copy link
Author

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

@h4cc
Copy link
Collaborator

h4cc commented Feb 13, 2015

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 😩

@akovalyov
Copy link

Probably related bug - https://bugs.php.net/bug.php?id=64169.

@SnakeO
Copy link

SnakeO commented Jan 3, 2017

Same bug. PHP 5.5.9 : https://i.imgur.com/k6HPsvU.jpg

@topekTopperson
Copy link

topekTopperson commented May 24, 2017

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);
    }
}

@halfer
Copy link

halfer commented Jul 2, 2017

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?

GinoPane pushed a commit to GinoPane/php-ssh that referenced this issue Feb 19, 2020
@GinoPane
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants