Question:
Connect to SFTP server through php script?
indu_vinny
2006-04-25 23:51:05 UTC
Hi all,

How can i connect to a remote SFTP server through php script.
Anyone please help me on this.

Thanks & Regards,
Indrani
Five answers:
anonymous
2006-04-27 16:13:14 UTC
You can find the necessary code and example here:



http://us2.php.net/manual/en/function.ftp-connect.php



Good luck!
anonymous
2016-12-29 12:25:09 UTC
Sftp Php
?
2016-09-30 05:48:42 UTC
Php Sftp
Don T
2006-04-29 21:15:59 UTC
As previously answered, the PHP manual is a good place to look, but the FTP functions won't be much help. Look at the Secure Shell (SSH) functions and you will find direct support for SFTP.



You will need:



OpenSSL

libssh2

ssh2.so (PHP extension).



The attached source reference link provides detailed information and a list of any functions you will need to get SFTP up and running. (For non-interactive sessions, consider scp; it's easier to script and usually supported at any site offering SFTP services).



Added:



If you cannot use a php extension for some reason, you might consider using the sftp (or scp) client from openssh, called using the PHP system() function.



But sftp is interactive, so scripting responses becomes a problem here (read from file, perhaps? Or use the expect library?) Use scp with keys, if you can, to avoid the interactive problem.



If you resort to using "system()", be sure to clean any user-supplied data used in the parameter list; it MUST be cleansed! In general, this should be a last resort due to the security implications.
?
2016-03-18 04:17:36 UTC
The issue is that you are on a windows server which does not come comiled with php. Move to a linux server.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...