简体   繁体   English

如何使用ftp从服务器下载文件以及如何将该文件保存在本地文件夹中

[英]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.

相关问题 如何使用ftp从Windows服务器下载文件? - how to download a file from windows server using ftp? 如何从另一个 ftp 服务器将文件下载到我的服务器 - How can i download a file to my server, from another ftp server 如何从服务器上的ftp下载文件,然后从中使用导入数据 - How to download a file from ftp on server and then use import data from it 从FTP服务器下载CSV文件以保存到本地并进行上传 - Download CSV file from FTP server to save locally and process for Uploading PHP-从链接下载pdf文件并保存在本地文件夹中 - PHP - download pdf file from link and save in local file folder 如何从FTP下载文件并使用PHP将其流式传输到客户端 - How to download a file from FTP and stream it to client using PHP 如何使用php将文件夹从Web服务器下载到本地计算机 - How to download a folder from web server to local machine using php 当我下载文件或将文件添加到Laravel的本地计算机下载文件夹中时,如何在数据库中保存文件名。 这个东西的任何想法 - How to save a file name in my DB when I download or add a file into my local machine download folder in Laravel. any idea for this thing 直接从 URL 下载文件到本地文件夹或远程服务器中的文件夹 - Download file directly from URL to local folder or a folder in remote server 如何使用CURL将文件下载并保存到本地路径 - How to download and save a file to local path using CURL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM