Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:23:41+00:00 2026-05-30T19:23:41+00:00

How can I check if a specific file exists on a remote server using

  • 0

How can I check if a specific file exists on a remote server using PHP via FTP connections?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:23:43+00:00Added an answer on May 30, 2026 at 7:23 pm

    I used this, a bit easier:

    // 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 "<br>";
                echo "I found ".$check_file_exist." in directory : ".$path;
            }
            else
            {
                echo "<br>";
                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);
    

    Functions used: (thanks to middaparka)

    1. Login using ftp_connect

    2. Get the remote file list via ftp_nlist

    3. Use in_array to see if the file was present in the array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I check file permissions , without having to run operating system specific
How can I check a string in php for specific characters such as '#'
How can I check who has a specific file checked out in TFS? In
In C#, how do I check if a specific file exists in a directory
Visual Studio Test can check for expected exceptions using the ExpectedException attribute. You can
I want to quickly check to see if a file exists in my iPhone
How can I check if a specific word in a Word document is bold?
How can i check the colors of specific pixels in the image? The example
How can I limit my php file that I use in ajaxRequest.open to be
Can check out here alt text http://51hired.com/static/problem.bmp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.