使用php从ftp下载文件
我试图使一个应用程序中,管理员将能够看到从特定文件夹(预定义)的文件,应该能够下载他们一个接一个。这些文件将存储在服务器上。有人能指导我怎么做吗?检查功能。它能满足你的需要 例如:使用php从ftp下载文件,php,ftp,Php,Ftp,我试图使一个应用程序中,管理员将能够看到从特定文件夹(预定义)的文件,应该能够下载他们一个接一个。这些文件将存储在服务器上。有人能指导我怎么做吗?检查功能。它能满足你的需要 例如: <?php $file_content = file_get_contents ('ftp://mysite.com/file.txt'); ?> 然后,您只需使用或将内容写入文件系统即可(根据您的喜好)。您正在尝试获取远程FTP服务器中的文件列表吗?如果是这样,那么您需要使用PEAR中的Net-F
<?php $file_content = file_get_contents ('ftp://mysite.com/file.txt'); ?>
然后,您只需使用或将内容写入文件系统即可(根据您的喜好)。您正在尝试获取远程FTP服务器中的文件列表吗?如果是这样,那么您需要使用PEAR中的Net-FTP2扩展(遗憾的是,它已经被放弃了,但是您可以从那里挽救一些代码) 至于将来自FTP服务器的特定文件提供给远程用户,我建议
请记住,您还需要添加适当的标题,如内容类型、内容长度等,readfile手册页面中有一些示例。我知道这是一个老问题,但我正在搜索类似的解决方案,我认为这将是一个有用的答案,它正在工作。 我希望它能帮助别人
<?php
//ftp-server
$connection_id = ftp_connect("here put the link of FTP server");
$ftp_username = "here the username";
$ftp_password = "here the password";
$file_path_my_pc = "here the path that you want to save your file..";
$file_path_ftp_server = "here the path of the file in FTP server/the name of file.csv";
$login = ftp_login($connection_id, $ftp_username, $ftp_password);
if (!$login) {
echo "Connection to ftp server has failed!! ";
exit;
} else {
echo "Connected has be done!!";
}
ftp_pasv($connection_id, true);
if (ftp_get($connection_id, $file_path_my_pc.'/here the name of your file in the FTP server', $file_path_ftp_server, FTP_ASCII)) {
echo "File has been downloaded!!";
ftp_close($connection_id);
return true;
} else {
ftp_close($connection_id);
echo "fail ... ";
echo "Connected has be stopped!!";
return false;
}
不起作用,因为无法使用file\u get\u内容获取目录的文件列表。是的,我认为get file\u get\u内容不起作用。我想显示文件列表,让管理员可以下载。我想解释一下我的情况。服务器上有一个文件夹,比如XXXX。一旦用户完成一组问题,XXXX文件夹就会更新(文件会自动添加到其中)。现在,我想设计一个应用程序,管理员将能够看到文件的名称,并将能够下载他们一个一个点击一个按钮。你可以指导我,并为我提供一个样本代码,这将是伟大的。所以,开始实施它,并问你是否遇到问题。你确定这里涉及到FTP吗?
<?php
//ftp-server
$connection_id = ftp_connect("here put the link of FTP server");
$ftp_username = "here the username";
$ftp_password = "here the password";
$file_path_my_pc = "here the path that you want to save your file..";
$file_path_ftp_server = "here the path of the file in FTP server/the name of file.csv";
$login = ftp_login($connection_id, $ftp_username, $ftp_password);
if (!$login) {
echo "Connection to ftp server has failed!! ";
exit;
} else {
echo "Connected has be done!!";
}
ftp_pasv($connection_id, true);
if (ftp_get($connection_id, $file_path_my_pc.'/here the name of your file in the FTP server', $file_path_ftp_server, FTP_ASCII)) {
echo "File has been downloaded!!";
ftp_close($connection_id);
return true;
} else {
ftp_close($connection_id);
echo "fail ... ";
echo "Connected has be stopped!!";
return false;
}