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"; } ?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号