我需要创建 2 个函数:一个使用 SFTP 上传文件,另一个使用 SCP。我正在使用phpseclib和put
方法;我相信我已经完成了 SFTP 功能。
现在,我正在尝试执行 SCP 功能。根据http://adomas.eu/phpseclib-for-ssh-and-scp-connections-with-php-for-managing-remote-server-and-data-exchange/,似乎以下是我需要的东西去做:
In case of SCP:
1. Including the needed file: include('/path/to/needed/file/Net/SFTP.php');
2. Creating object and making connection:
$sftp = new Net_SFTP('host');
if (!$sftp->login('user', 'password')) { exit('Login Failed'); }
3. Reading contents of a file: $contents=$sftp->get('/file/on/remote/host.txt');
4. Copying file over sftp with php from remote to local host: $sftp->get('/file/on/remote/host.txt', '/file/on/local/host.txt');
5. Copying file over sftp with php from local to remote host: $sftp->put('/file/on/remote/host.txt', '/file/on/local/host.txt');
6. Writing contents to remote file: $sftp->get('/file/on/remote/host.txt', 'contents to write');
我需要做#5,但它看起来就像我为 SFTP 所做的一样。SFTP 和 SCP 不一样,对吧?相同的代码是否正确?如果没有,我该怎么做 SCP?