how to connect to an ftp server

0

I have this code I wanted to call me at ftp . By the browser I can, but by the code tells me that it can not log in.

Follow the code, I hid the data:

$ftp_server = "" ;
$ftp_user_name = "" ;
$ftp_user_pass = "" ;
$depth = 10;

$conn_id = ftp_connect($ftp_server) ;
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (!$login_result) { die("Couldn't log in to FTP account."); }

$dir = array(".");
$a = count($dir);
$i = 0;
while (($a != $b) && ($i < $depth)) {
  $i++;
  $a = count($dir) ;
  foreach ($dir as $d) {
    $ftp_dir = $d."/" ;
    $newdir = ftp_nlist($conn_id, $ftp_dir);
    foreach ($newdir as $key => $x) {
      if ((strpos($x,".")) || (strpos($x,".") === 0)) { unset($newdir[$key]); }
      elseif (!in_array($x,$dir)) { $dir[] = $x ; }
    }
  }
  $b = count($dir) ;
}

print_r($dir) ;

ftp_close($conn_id);

?>
    
asked by anonymous 26.01.2016 / 10:52

1 answer

0

Live,

I usually use this class you find in github: link

$ftp = new \FtpClient\FtpClient();
$ftp->connect($host, true, 22);
$ftp->login($login, $password);
$ftp->putAll($source_directory, $target_directory);

It is very easy to use, and has a superb error control;) You can also sign in for ssl.

    
26.01.2016 / 11:25