[英]How to download a file from server using ftp and how to save that file in my local folder
this is my code but this is not working whats a problem in this code.u have any another code.give me idea to download a file from server using ftp.i am trying this code in my localhost also in my own server. 这是我的代码,但无法正常工作,这是此代码中的问题。你还有其他代码。给我一个想法,可以使用ftp从服务器下载文件。我也在自己的本地主机中尝试此代码。
$curl = curl_init();
$file = fopen("ftpfile/file.csv", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp:http://www.address.com/file.csv"); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "myusername:mypassword");
curl_exec($curl);
I'm guessing one of two things: the fopen call failed (and you're not checking if it succeeded by seeing if $file !== false
), or the double-use of _returntransfer AND _file is not acting as you expect. 我猜是两件事之一:fopen调用失败(并且您没有通过查看
$file !== false
检查它是否成功),或者_returntransfer和_file的双重使用未达到您的预期。
returntransfer tells curl to return the retrieved data in the exec call, instead of outputting it directly to the browser. returntransfer告诉curl在exec调用中返回检索到的数据,而不是直接将其输出到浏览器。 I suspect that if you did
$data = curl_exec($curl); file_put_contents('ftpfile/file.csv', $data)
我怀疑如果您这样做
$data = curl_exec($curl); file_put_contents('ftpfile/file.csv', $data)
$data = curl_exec($curl); file_put_contents('ftpfile/file.csv', $data)
you'd end up with a properly populatd file. $data = curl_exec($curl); file_put_contents('ftpfile/file.csv', $data)
会以适当的populatd文件结尾。 So... either remove the returntransfer option, or eliminate the whole _file business and output the file yourself using what the _exec call returns. 因此,...要么删除returntransfer选项,要么取消整个_file业务,并使用_exec调用返回的内容自己输出文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.