[英]ftp_get giving error while fetching a file
Im trying to fetch a csv file from a remote server with ftp_get 我正在尝试使用ftp_get从远程服务器获取CSV文件
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, TRUE);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$okk=0;
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) (line 31)
{
$okk=1;
}
but its giving following error 但它给以下错误
Warning: ftp_get(): Opening BINARY mode data connection for /abc/abc.csv(198528 bytes). 警告:ftp_get():为/abc/abc.csv(198528字节)打开BINARY模式数据连接。 in /home/a/b/c/cm_data/d.php on line 31 在第31行的/home/a/b/c/cm_data/d.php中
I tried changing it to ascii mode then too it gave error 我尝试将其更改为ASCII模式然后也给出了错误
Warning: ftp_get(): Opening ASCII mode data connection for /abc/abc.csv(198528 bytes). 警告:ftp_get():为/abc/abc.csv(198528字节)打开ASCII模式数据连接。 in /home/a/b/c/cm_data/d.php on line 31 在第31行的/home/a/b/c/cm_data/d.php中
i also tried using ftp_pasv($conn_id, TRUE);
我也尝试使用ftp_pasv($conn_id, TRUE);
too but still gives error. 也是,但仍然给出错误。
What is the problem please help!! 有什么问题请帮忙!!
ftp_login 之后需要调用ftp_pasv!
You seem not to treat error cases from ftp_connect
and ftp_login
. 您似乎不考虑ftp_connect
和ftp_login
错误情况。
Please try the following code and see if it gives some errors: 请尝试以下代码,看看是否提供了一些错误:
<?php
$ftp_server = $ftp_server;
$ftp_user = $ftp_user_name;
$ftp_pass = $ftp_user_pass;
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n";
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
$okk=1;
}
} else {
echo "Couldn't connect as $ftp_user\n";
}
// close the connection
ftp_close($conn_id);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.