我遇到过很多用于Web FTP客户端的PHP脚本.我需要在PHP中将SFTP客户端实现为Web应用程序.PHP是否支持SFTP?我找不到样品.谁能帮我这个?
我已成功通过ftp上传文件,但我现在需要通过SFTP完成.我可以成功连接到远程服务器,创建文件并写入,但我无法将现有文件从本地服务器上传到远程服务器.ftp_put是否没有使用sftp连接触发?
我的代码用来写一个文件:
//Send file via sftp to server
$strServer = "*****";
$strServerPort = "****";
$strServerUsername = "*****";
$strServerPassword = "*****";
$csv_filename = "Test_File.csv";
//connect to server
$resConnection = ssh2_connect($strServer, $strServerPort);
if(ssh2_auth_password($resConnection, $strServerUsername, $strServerPassword)){
//Initialize SFTP subsystem
echo "connected";
$resSFTP = ssh2_sftp($resConnection);
$resFile = fopen("ssh2.sftp://{$resSFTP}/".$csv_filename, 'w');
fwrite($resFile, "Testing");
fclose($resFile);
}else{
echo "Unable to authenticate on server";
}
Run Code Online (Sandbox Code Playgroud)
有没有人在抓取本地文件并通过sftp上面的方法上传?一个例子将不胜感激.
谢谢