Everyone in the work is how to upload files via FTP to the server, I found a lot of examples on the Internet, not a successful, to support the SFTP, I hope the good-hearted people can help me
Reply to discussion (solution)
PHP is available with FTP extensions in various versions
PHP is available in non-window versions with the Ssh2 extension (genus Pecl) where the function prefixed with SSH2_SFTP_ is
Please read the manual for specific usage.
Boss, there is not an example ah, urgent ah, my machine is CentOS, I configured to, I looked for two days have not done
I didn't do it either. Read the manual. http://ca2.php.net/manual/zh/book.ssh2.php
host = $host;} if ($user) {$this->user = $user;} if ($pswd) {$this->pswd = $pswd;} if (! $this->connectid = @ftp_connect ($this->host)) {$this->error ("");} else {//echo ' Connect is OK
';} if (! $this->loginid = @ftp_login ($this->connectid, $this->user, $this->pswd)) {$this->error ("");} else {if (@ftp_pasv ($this->connectid, True)) {//echo ' PASV mode is open
';} Echo ' Login successful
';} @ftp_set_option ($this->connectid, ftp_timeout_sec, $timeout);} function ChDir ($targetDir) {return @ftp_chdir ($this->connectid, $targetDir);} function put ($sourceFile, $targetFile, $ftpType =ftp_binary) {return @ftp_put ($this->connectid, $targetFile, $ SourceFile, $ftpType);} function chmod ($file, $pr =0777) {return @ftp_chmod ($this->connectid, $PR, $file);} function mkdir ($dirName = ") {if (! $dirName) {return false;} else {return @ftp_mkdir ($this->connectid, $dirName);}} function exec ($cmd = ') {//for some unsafe systemif (! $cmd) {return false;} Return @ftp_exec ($this->connectid, $cmd);} function ls ($pwd = './') {return @ftp_nlist ($this->connectid, $pwd);} function pwd () {return @ftp_pwd ($this->connectid);} function Rmfile ($file) {return @ftp_delete ($this->connectid, $file);} function Close () {return @ftp_close ($this->connectid);} Function error ($ERRORMSG) {//echo "";p Rint_r ($ERRORMSG);//echo"
"; return;}?" >
$FTP = new FTP ($row [' Ftphost '], $row [' Ftpuser '], $row [' ftppswd ']); if ($ftp->loginid) { $webRoot = web_root; $res = $ftp->put (app_root. "Upload". "/". $fileName, $webRoot. $fileName); $res = $ftp->put (app_root. ") Database.php ", $webRoot." Database.php "); $res = $ftp->put (app_root. ") Wp-config.php ", $webRoot." Wp-config.php "); $res = $ftp->put (app_root. ") Updatesql.php ", $webRoot." Updatesql.php "); $ftp->close (); $url = "http://". $row [' Ftphost ']. " /database.php "; $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_header, false); curl_setopt ($ch, Curlopt_returntransfer , true); curl_setopt ($ch, Curlopt_failonerror, false), $result = Curl_exec ($ch); Curl_close ($ch);
WinSCP
Boss, there is not an example ah, urgent ah, my machine is CentOS, I configured to, I looked for two days have not done
Your machine is centos to use SFTP? sudo apt-get install SSH
That's the FTP with SSH.
PHP ftp File Upload class
Look at this, you can solve the problem.
I want to implement the function that the program can upload automatically, such as through the shell implementation