FTP get all files

2019-04-28 13:16发布

I have successfully connected to my FTP using PHP and I can see all the files using: ftp_nlist

But, is there an easy way to then download all these files in the current directory?

I can't see to find any examples of how I'd do this.

Thanks

标签: php ftp
3条回答
劳资没心,怎么记你
2楼-- · 2019-04-28 13:41

Try using ftp_get()

$local_file = 'filename.txt';
$server_file = 'filename.txt';

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}

ftp_close($conn_id);
查看更多
在下西门庆
3楼-- · 2019-04-28 13:46

Another simple solution is ....

List the files in an array and download each file individually.

Something like:

$contents = ftp_nlist($conn_id, ".");

foreach ($contents as &$value) { $result = ftp_fget($conn_id, $local,&$value, FTP_BINARY); }

You might need to tweak the code a little...

查看更多
Explosion°爆炸
4楼-- · 2019-04-28 14:01

Yes there is. NanoFTPD is an old project from around 2003. It uses PHP to listen on the FTP port and handles all requests from the client. It is able to do all the functionalities including downloading (all) files to whatever directory you want. Take a look here

查看更多
登录 后发表回答