我正在尝试通过 ftp 将 zip 文件从一台服务器传输到我的服务器,以便我可以使用文件中的数据来更新我的数据库表。这是我的 ftp.php 文件:
<?php
header('Content-type: text/html; charset=utf-8');
$date = "2013-05-21-11-19-40";
$ftp_server="ftp.server.com";
$ftp_user_name="BookCellar";
$ftp_user_pass="*****";
$file = "/reports/other/compreport_abebooks_" .$date. ".zip";//tobe uploaded
$remote_file = "/chroot/home/bookcellaronline.com/html/testbcos/accounting/compreport_abebooks_" .$date. ".zip";
?>
我的 ftpUpload.php 文件是:
<?php
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file));
header('Content-Type: application/zip');
require_once('ftp.php');
// set up basic connection
$conn_id = ftp_ssl_connect($ftp_server);//ftp_connect
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// check connection
if ((! $conn_id ) || (! $login_result )) {
echo "FTP connection has failed!" ;
exit;
} else {
echo "Connected for user $ftp_user_name" ;
}
ftp_chdir($conn_id, '/home/bookcell/bookcellaronline.com/html/testbcos/accounting/');
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
echo $php_errormsg;
// close the connection
ftp_close($conn_id);
?>
当我运行这些时,我收到错误消息:
[<a href='function.ftp-put'>function.ftp-put</a>]: failed to open stream: No such file or directory in /chroot/home/bookcell/bookcellaronline.com/html/testbcos/accounting/ftpUpload.php on line 25
第 25 行是:
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
我研究了一堆关于 SO 的其他帖子,但没有找到解决方案。我的连接有效,但我无法传输文件。我如何(如果可能)将其传输到我的服务器?
编辑:我是否错过了我不仅需要连接到他们的服务器($file)和我的服务器($remote_file)的事实????