Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I used this, a bit easier:</p> <pre><code>// the server you wish to connect to - you can also use the server ip ex. 107.23.17.20 $ftp_server = "ftp.example.com"; // set up a connection to the server we chose or die and show an error $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); ftp_login($conn_id,"ftpserver_username","ftpserver_password"); // check if a file exist $path = "/SERVER_FOLDER/"; //the path where the file is located $file = "file.html"; //the file you are looking for $check_file_exist = $path.$file; //combine string for easy use $contents_on_server = ftp_nlist($conn_id, $path); //Returns an array of filenames from the specified directory on success or FALSE on error. // Test if file is in the ftp_nlist array if (in_array($check_file_exist, $contents_on_server)) { echo "&lt;br&gt;"; echo "I found ".$check_file_exist." in directory : ".$path; } else { echo "&lt;br&gt;"; echo $check_file_exist." not found in directory : ".$path; }; // output $contents_on_server, shows all the files it found, helps for debugging, you can use print_r() as well var_dump($contents_on_server); // remember to always close your ftp connection ftp_close($conn_id); </code></pre> <p>Functions used: (thanks to middaparka)</p> <ol> <li><p>Login using <a href="http://www.php.net/manual/en/function.ftp-connect.php">ftp_connect</a></p></li> <li><p>Get the remote file list via <a href="http://www.php.net/manual/en/function.ftp-nlist.php">ftp_nlist</a></p></li> <li><p>Use <a href="http://www.php.net/manual/en/function.in-array.php">in_array</a> to see if the file was present in the array</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload