>백엔드 개발 >PHP 튜토리얼 > 关于FTP上传文件有关问题

关于FTP上传文件有关问题

WBOY
WBOY원래의
2016-06-13 12:48:23812검색

关于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 "
";
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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.