我正在尝试将csv文件从FTP移到公共URL,或者试图从PHP代码下载文件。我已经成功使用php脚本登录,但是无法从浏览器上的FTP下载文件。
<?php
// define some variables
$ftp_server="xyz";
$ftp_user_name="xyz";
$ftp_user_pass="xyz";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$file = 'dealerpricelist.csv';
$fp = fopen($file, 'w');
// Initate the download
$ret = ftp_nb_fget($conn_id, $fp, $file, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// Do whatever you want
echo ".";
// Continue downloading...
$ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
echo "There was an error downloading the file...";
exit(1);
}
// close filepointer
fclose($fp);
?>
<?php
$local_file = 'p.csv';
$server_file = 'dealerpricelist.csv';
$ftp_server="xyz";
$ftp_user_name="xyz";
$ftp_user_pass="xyz";
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
}
else {
echo "There was a problem\n";
}
ftp_close($conn_id);
?>
我无法下载此文件。实际结果应该是文件应该从浏览器中的FTP下载。