SFTP from within PHP

22,724

Solution 1

Yes, you can do that with cURL. To switch from FTP to SFTP all you have to do is to change protocol option form CURLPROTO_FTP to CURLPROTO_SFTP.

cURL supports following protocols: HTTP, HTTPS , FTP, FTPS, SCP, SFTP, TELNET, LDAP, LDAPS, DICT, FILE, TFTP.

BTW. SFTP is not to be confused with FTPS. SFTP is SSH File Transfer Protocol, while FTPS is FTP over SSL.

Solution 2

if you don't have cURL installed (my host doesn't), you can use phpseclib:

http://phpseclib.sourceforge.net/documentation/net.html#net_sftp

Solution 3

In case someone end-up on this page.

You also may use the PHP Bindings for LIBSSH2 with PHP. It should be appropriately installed on the system.

In Ubuntu 10.04 and Debian Lenny, of course with all dependences

apt-get install libssh2-php
Share:
22,724
Slavik Okara
Author by

Slavik Okara

I'm a 24 years old guy from Sibiu, Romania studying marketing and economics and interested in the area of web development. http://www.enhanced.ro

Updated on February 04, 2020

Comments

  • Slavik Okara
    Slavik Okara over 4 years

    I'm in the process of building an web app that will, besides other things, need to connect to a FTP server to download or upload files. The application is written in PHP and it's hosted on a Linux server.

    What I was wondering is whether or not it would be possible to also provide support for SFTP servers, but after some quick searches on Google it seems that this is not all that simple.

    So, the question is: What would be the best way to use SFTP from within PHP? Is there a class that could also provide support for FTP as well as SFTP so that same functions could be used for both?