关于FTP上传文件有关问题

WBOY
Release: 2016-06-13 12:48:23
Original
784 people have browsed it

关于FTP上传文件问题
各位在工作是如何通过FTP上传文件到服务器上,我在网上找了很多例子,没有一个成功的,要支持SFTP的,希望好心人能帮帮我

sftp?ftp
------解决方案--------------------
我也没弄过,看手册吧 http://ca2.php.net/manual/zh/book.ssh2.php
------解决方案--------------------
<?php<br />
class Ftp {<br />
	var $host;<br />
	var $user;<br />
	var $pswd;<br />
	var $connectId = null;<br />
	var $loginId = null;<br />
		<br />
	function Ftp($host, $user, $pswd, $timeout=900){<br />
		if($host) {<br />
			$this->host = $host;<br />
		}<br />
		if($user) {<br />
			$this->user = $user;<br />
		}<br />
		if($pswd) {<br />
			$this->pswd = $pswd;<br />
		}<br />
		if(!$this->connectId = @ftp_connect($this->host)) {<br />
			$this->error("");<br />
		}<br />
		else {<br />
			//echo 'connect is ok<br />';<br />
		}<br />
		if(!$this->loginId = @ftp_login($this->connectId, $this->user, $this->pswd)){<br />
			$this->error("");<br />
		}<br />
		else {<br />
			if(@ftp_pasv($this->connectId, true)) {<br />
				//echo 'pasv mode is open<br />';<br />
			}<br />
			//echo 'login successful<br />';<br />
		}<br />
		@ftp_set_option($this->connectId, FTP_TIMEOUT_SEC, $timeout);<br />
	}<br />
	<br />
	function chdir($targetDir) {<br />
		return @ftp_chdir($this->connectId, $targetDir);<br />
	}<br />
	<br />
	function put($sourceFile, $targetFile, $ftpType=FTP_BINARY) {<br />
		return @ftp_put($this->connectId, $targetFile, $sourceFile, $ftpType);<br />
	}<br />
	function chmod($file, $pr=0777){<br />
		return @ftp_chmod($this->connectId, $pr, $file);<br />
	}<br />
	function mkdir($dirName=''){<br />
		if(!$dirName) {<br />
			return false;<br />
		}<br />
		else {<br />
			return @ftp_mkdir($this->connectId, $dirName);<br />
		}<br />
	}<br />
	<br />
	function exec($cmd=''){ //for some unsafe system<br />
		if(!$cmd){<br />
			return false;<br />
		}<br />
		return @ftp_exec($this->connectId, $cmd);<br />
	}<br />
	<br />
	function ls($pwd='./') {<br />
		return @ftp_nlist($this->connectId, $pwd);<br />
	}<br />
	<br />
	function pwd() {<br />
		return @ftp_pwd($this->connectId);<br />
	}<br />
	<br />
	function rmFile($file) {<br />
		return @ftp_delete($this->connectId, $file);<br />
	}<br />
	<br />
	function close(){<br />
		return @ftp_close($this->connectId);<br />
	}<br />
	<br />
	function error($errorMsg) {<br />
		//echo "<pre class="brush:php;toolbar:false">";<br />
		print_r($errorMsg);<br />
		//echo "
Copy after login
";
return;
}
}
?>

  $ftp = new Ftp($row['ftpHost'], $row['ftpUser'], $row['ftpPswd']);<br>
	        if($ftp->loginId) {<br>
	        	<br>
		        	$webRoot = WEB_ROOT;<br>
	        	<br>
	            $res=$ftp->put(APP_ROOT. "upload". "/". $fileName, $webRoot. $fileName);<br>
	            $res=$ftp->put(APP_ROOT."database.php", $webRoot."database.php");<br>
	            $res=$ftp->put(APP_ROOT."wp-config.php", $webRoot."wp-config.php"); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template