How to do SFTP?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I need to be able to connect to an SFTP server on the usual port 22.
How would I go about doing this? I tried using the SSH2 thing shown in
the annotated manual, but no luck. It looks like my PHP wasn't
compiled with the right libraries. Is there a away to do SFTP without
me recompiling my PHP? I just need to connect to a server and upload a
file. Nothing too complex.

Re: How to do SFTP?

D. Finnigan wrote:
Quoted text here. Click to load it

How do you know the libraries aren't compiled in?  What error message(s)
do you get?

You need the libraries loaded either at compilation time or dynamically
with extension=php_ssh2.dll (assuming Windows - .so for Linux.  Of
course the you must also have the OpenSSL libraries installed on your
system and available to PHP at load time.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: How to do SFTP?

Quoted text here. Click to load it

Assuming that you can't load the libraries either, then you could just
invoke the corresponding CLI tools (assuming they are installed) -
using popen, exec etc. This will be a lot easier if you have a key-
pair configured for the connection (you don't need to provide a
password). If I recall correctly, scp will fail over to sftpbased
transport automatically and all the behaviour can be specified on the
command line - while sftp requires you toprovide the operation
specific commands after establishing a session.


Re: How to do SFTP?

On Tue, 15 Sep 2009 17:42:01 -0500, D  Finnigan wrote:
Quoted text here. Click to load it

If your php installation has access to it, you can shell out to the OS
level and use such command-line tools are available there. There's
several ways to do that, all listed at

Be very careful when using these -- there's lots of ways that they can
be abused if your PHP takes user input for anything involving the command
construction. (If you think SQL injection is bad, you'll be shaken by
the amount of devastation a shell injection can cause.)

61. If my advisors ask "Why are you risking everything on such a mad scheme?",
    I will not proceed until I have a response that satisfies them.
                --Peter Anspach's list of things to do as an Evil Overlord

Re: How to do SFTP?

Quoted text here. Click to load it

It's a Linux server which I have shell access too. The script will be
running on my desktop, so there's no worry about user input-- I trust
myself. ;-)

The machine with PHP is an Intel iMac using the pre-installed PHP 5.2.8
as provided by Apple.

Running php -i shows that it's got OpenSSL 0.9.7l 28 Sep 2006

Re: How to do SFTP?

Quoted text here. Click to load it

There's this: /*checkout*/phpseclib/phpseclib/=

Site Timeline