Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 16, 2015 12:19
Show Gist options
  • Select an option

  • Save tamboer/5433736 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/5433736 to your computer and use it in GitHub Desktop.
php ftp connect
<?php
// connect
$ftp = ftp_connect("example.com");//or IP address as variable
if (!$ftp) die('could not connect.');
// login
$r = ftp_login($ftp, "anonymous", "");
if (!$r) die('could not login.');
// enter passive mode
$r = ftp_pasv($ftp, true);
if (!$r) die('could not enable passive mode.');
// get listing
$r = ftp_rawlist($ftp, "/");
var_dump($r);
//EXAMPLE Open images directory
$dir = opendir("images");
//List files in images directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "<br />";
}
closedir($dir);
/**
The output of the code above could be:
filename: .
filename: ..
filename: cat.gif
filename: dog.gif
filename: food
filename: horse.gif
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment