我想设置一个运行PHP脚本的CRON,然后将XML文件(保存非敏感信息)从一个服务器移动到另一个服务器.
我已获得正确的用户名/密码,并希望使用SFTP协议.这些工作将每天运行.一台服务器可能是Linux而另一台服务器是Windows.两者都在不同的网络上.
移动该文件的最佳方法是什么?
为什么不尝试使用PHP的FTP功能?
然后你可以这样做:
// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
Run Code Online (Sandbox Code Playgroud)
为什么不使用shell_exec和scp?
<?php
$output = shell_exec('scp file1.txt dvader@deathstar.com:somedir');
echo "<pre>$output</pre>";
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7844 次 |
| 最近记录: |