Last active
December 16, 2015 12:19
-
-
Save tamboer/5433736 to your computer and use it in GitHub Desktop.
php ftp connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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