我已成功通过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";
}
有人能否成功地通过像上面提到的sftp方式抓取本地文件并进行上传?如有示例将不胜感激。
谢谢
resFile
?为什么是“res”?它代表什么? - Black$strServerPassword
?我没有看到它被使用在这里。 - FerdousTheWebCoder