Jump to content

How to list or get all files of a remote folder via FTP?


giba

Recommended Posts

I solved it by myself,

so I will post here for who would like to save time when such a problems happen:

 

1) create a file on the server listing all files in such a directory:

 

[pictures.php]

<?php

$p = null;

foreach (glob("pictures/*.jpg") as $file) {

    $p .= $file.',';

}

 

$p .= 'end';

 

echo $p;

?>

 

2) get the content of this file from such a file:

 

[get-list.php]

$file= file_get_contents('http://www.server.com/path/to/file/pictures.php');

$file = str_replace(',end','',$file);

$f = explode(",",$file);

 

foreach ($f as $file) {

     /*

      * Any code here for get the files,

      * I used a class you can do it your way

      */

      $files->get($server, $local);

}

 

That's it, I solved it so!

 

Hi there guys!

I am trying to get all files of a remote folder via FTP,

but I got no sucess until now!

How could I do this?

 

here's a basic login=>get list=>print array of files/folders

<?php

// set up basic connection
$ftp_server = "example.com";
$ftp_user_name = "example_user";
$ftp_user_pass = "password";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// get the file list for /
$buff = ftp_nlist($conn_id, '/');

// close the connection
ftp_close($conn_id);

// output the buffer
print_r($buff);
?>

just realized you wanted the files, not just a list of files.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.