terrid25
terrid25

Reputation: 1946

FTP get all files

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

Upvotes: 7

Views: 11142

Answers (3)

Elyor
Elyor

Reputation: 5532

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);

Upvotes: 0

slotishtype
slotishtype

Reputation: 2761

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...

Upvotes: 7

user657496
user657496

Reputation:

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

Upvotes: 0

Related Questions