Home >Backend Development >PHP Tutorial >php sftp下传上载

php sftp下传上载

WBOY
WBOYOriginal
2016-06-13 10:53:56853browse

php sftp上传下载

	<?php		//php环境中必须有ssh		$strServer = "ftp.***.com.cn";		$strServerPort = "22";		$strServerUsername = "***";		$strServerPassword = "***";				//connect to server		$resConnection = ssh2_connect($strServer, $strServerPort);				if(ssh2_auth_password($resConnection, $strServerUsername, $strServerPassword)){			//init SFTP			$resSFTP = ssh2_sftp($resConnection);						//download a File			//1			$filename = 'c:/abc.jpg';			$opts = array(				'http'=>array(				'method'=>"GET",				'timeout'=>60,				)			);			$context = stream_context_create($opts);//			$strData = file_get_contents("ssh2.sftp://{$resSFTP}/dfr508/WUN/ikea-logo.jpg", false, $context);//			file_put_contents($filename, $strData);						//2 也可以用copy()			if(!copy("ssh2.sftp://{$resSFTP}/dfr508/WUN/ikea-logo.jpg", $filename)) {				echo 'download failed';			}						//upload a File			//1			//file_put_contents("ssh2.sftp://{$resSFTP}/dfr508/WUN/456.jpg", 'c:/123.jpg');			//2//			if(!copy("c:/abc.jpg", "ssh2.sftp://{$resSFTP}/dfr508/WUN/789.jpg")) {//				echo 'upload failed';//			}		} else {			echo "Unable to authenticate on server";		}	?>

Statement:
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