ftp_get()损坏的大文件下载 [英] ftp_get() corrupt large file download
问题描述
我必须使用ftp从服务器下载.gz格式的大文件(大约-9mb).我编写了一个函数,可以完全正确地下载文件,但是当我将此代码置于在线状态时,文件已下载但文件已损坏. 这是我的代码:
I have to download a large file(approx~-9mb) in .gz format from the server using ftp. I have written a function which downloads the file completely and correctly but when i put this code online , the file is downloaded but the file gets corrupt. Here is my code:
function downloadFile($ftp_server, $username, $password, $server_file, $local_file)
{
// download server file
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $username, $password);
ftp_pasv($ftp_conn, true);
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)) {
echo "Successfully written to $local_file.";
// exit;
} else {
echo "Error downloading $server_file.";
}
}
这就是我的称呼
ini_set('max_execution_time', 0);
$username = "username";
$password = "password";
$xmlFile = __DIR__ . "/monster.xml.gz";
$local_file = __DIR__ . "/monster.xml";
$ftp_server = "ftp.monster.com";
$server_file = "/US~Partner~Sample Feed.xml.gz";
downloadFile($ftp_server,$username,$password,$server_file,$xmlFile);
必须下载文件,然后将其转换为XML进行进一步处理. 注意:该文件正在localhost上完美下载,当我们将其放在实时服务器上时会发生此问题.
The file must be downloaded and the then I will convert it into XML for further processing. Note: The file is downloading perfect on localhost , this problem occurs as we put it on live server.
推荐答案
GZ文件中可能不仅包含文本.因此,您必须以二进制模式下载它,以便其中包含的所有内容都可以成功下载
GZ file may not only have text in it . So you have to download it with binary mode so that anything containing in it could be download successfully
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)) {
echo "Successfully written to $local_file.";
// exit;
} else {
echo "Error downloading $server_file.";
}
这篇关于ftp_get()损坏的大文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!