cronjob 通过 FTP 将文件复制到我们的服务器

cronjob to copy a file to our server via FTP

cron 作业是否可以从远程服务器复制文件并将其移动到我们的服务器并覆盖当前位于那里的文件?

我在这里寻找答案,但没有找到合适的解决方案,因为大多数人都在将文件移动到远程服务器而不是从远程服务器移动文件

将包含两组 ftp 详细信息。

这是一个产品供稿,我真的无法理解它。

我的思路是否正确?

<?php
$file = 'remotefile.txt';
$remote_file = 'ourfile.txt';
$ftp_server ='example.com';
$ftp_user_name = 'username';
$ftp_user_pass = 'password';



// 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);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

是的,这是可能的。 Cronjobs 用于定期执行脚本(每小时、每天等...)。

所以你可以用脚本做的一切,你也可以用 cronjobs 做。

在玩弄代码后我注意到我使用的是 ftp_put 而不是 ftp_get

这是工作代码

<?php
$file = 'remotefile.txt';
$remote_file = 'ourfile.txt';
$ftp_server ='example.com';
$ftp_user_name = 'username';
$ftp_user_pass = 'password';



// 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);

// upload a file
if (ftp_get($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>