通过SFTP将文件从本地Linux服务器传输到远程Linux服务器
问题描述:
我可以用同一台计算机上的文件从一个文件夹传输到另一个文件夹。通过SFTP将文件从本地Linux服务器传输到远程Linux服务器
$file = 'pdf.pdf';
$source_path = 'source/';
$target_path = 'target/';
if (! copy($source_path . $file, $target_path . $file))
{
exit('Failed to copy ' . $source_path . $file);
}
echo $source_path . $file . ' file copied to ' . $target_path . $file;
我想将它传输到使用SFTP-SSH的远程Linux服务器上,我该怎么做呢?如果有人问,我发现了很多例子来理解使用cURL(),ftp_get(),stream_copy_to_stream(),ssh2_sftp(),scp()的逻辑,但是由于之前从未做过,所以未能实现它。
注意:我的设置下面的FileZilla工作正常。
target host: https://192.168.32.1/test_folder/
target host: https://mysite.site.com/test_folder/
protocol: SFTP-SSH
port: 2281
username: myusername
password: mypassword
感谢