SFTP from within PHP
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.
if you don't have cURL installed (my host doesn't), you can use phpseclib:
http://phpseclib.sourceforge.net/documentation/net.html#net_sftp
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
The problem with Igor's recommendation is that it, among other things, makes for much less portable code (libssh2 isn't installed on very many hosts), it has a far more intuitive OOP-based API and RSA authentication actually makes sense (libssh2 requires you store the public key and the private key separately on the file system; the fact that they have to be separately provided is silly since most private key formats include the public key within them).
phpseclib is also faster:
http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/#comment_3759