T
T
therekey2017-01-30 14:06:55
JavaScript
therekey, 2017-01-30 14:06:55

How to display the number of files in a specific folder on another server via FTP, on the site screen?

How to display the number of files in a certain folder on another server via FTP on the site screen?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anton_lazarev, 2017-01-30
@therekey

$ftp = ftp_connect('ftp.example.com');

ftp_login($ftp, 'username', 'password');

$files = ftp_nlist($ftp, '/path/to/dir');

var_dump(count($files));

ftp_close($ftp);

A
Alexey Burlaka, 2017-01-30
@AlexeyGfi

ajax+php
Through ajax make a request, through php connect via ftp.
Code example:

$ftp_login= "ftp_login";
$ftp_pass= "ftp_pass";
  
//Коннектимся к ftp, получаем список файлов
$conn_id = ftp_connect ( "domain.site.com" ); 
  
$login_result = ftp_login ( $conn_id, $ftp_login, $ftp_pass ); 
//Провеяем $login_result

//Заходим внутрь нужной папки. Типа комманда "cd"
if ( !ftp_chdir($conn_id, "www")) { 
  echo "Couldn't change directory"; 
  die; 
}

//Получаем список файлов и папок "там"
$ftp_nlist= ftp_nlist( $conn_id, "." );
  
foreach ($ftp_nlist as $v) {
  //$v — название файла, папки. Делаем что-нибудь с ним
  //Например, копируем к себе: ftp_get
  //Например, удаляем на фтп: ftp_delete
} //end foreach 
  
ftp_close($conn_id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question