通过SFTP将文件从本地Linux服务器传输到远程Linux服务器

时间:2013-10-09 15:05:42

标签: php

我可以在同一台计算机上将文件从一个文件夹传输到另一个文件夹,其下面的代码是工作文件。

$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

由于

1 个答案:

答案 0 :(得分:1)

我自己从未尝试过,但是phpseclib似乎非常有希望:http://phpseclib.sourceforge.net/sftp/examples.html#put