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 6082871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:20:14+00:00 2026-05-23T11:20:14+00:00

My web server is running on one server, and the data fetching is running

  • 0

My web server is running on one server, and the data fetching is running on another server. My code will try copy a remote file and store it in my local path. The remote location is, for example, /home/testUser/remoteData.xml. I know the server IP address and hostname. How can I construct the path to fill in the remotePath?

#remotePath is the path to the file on the network
public function __construct()
{
   $this->localPath="currentData.xml";
   $this->remotePath="a remote path";
}

#this will attempt to make a copy from that network file and store it locally
private function fetchServer()
{
   if (!(file_exists($this->remotePath)) || (time() - filectime($this->remotePath)) >= 1200)
      return false;
   else
   {  $success = copy($this->remotePath, $this->localPath);
      if($success)
         return true;
      else
         return false;
   }
}

Thank you very much!

  • 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-23T11:20:14+00:00Added an answer on May 23, 2026 at 11:20 am

    If you’re using HTTP, you won’t be able to check the creation time. If you know that it is a small, manageable file, you can use file_get_contents:

     $fl = @file_get_contents( '<stream>' );
     if( !$fl ) return false; // file does not exist remotely
     $ret = @file_put_contents( '<output name>', $fl );// just output it
     return $ret && true; //force it to boolean
    

    If it is a bit larger, you can use the cURL and stream syntax, or you can do something similar to what I did above:

     $fl = @fopen( '<stream>' );
     if( !$fl ) return false;// file does not exist remotely
     $out = @fopen( '<local file>', 'w');
     if( !$out ) return false;
     while($data = fread($fl)){fwrite($out,$data);}
     fclose($out);
     return true;
    

    Of course, all situations you will have to download the file to a local version and then do some form of checksum to see if there is a difference.

    EDIT


    You just mentioned that timestamp is a requirement but that you also have SSH. If you have SSH, then you might be able to use SFTP (which is something that piggy-backs off of SSH). I have used phpseclib for several projects and, while not perfect (it is in PHP4 and it does not truly tunnel for SSH), it is a very impressive library nevertheless. Look at the networking part of the manual and (if I remember) it will give you more than enough to do what you’re asking for.

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

Sidebar

Related Questions

I have 2 servers setup at the moment. One is a web server running
I'm running a nodejs / socket.io (v 0.7) server to push data to web
We have developed one Web Application which is running in only one server. Now
My production environment involves a pair of IIS 6 web servers, one running legacy
I have a Delphi Web Server setup and running, publishing Web Services, and I
Scenario: Take a server running .NET 3.0 and an ASP.NET Web site running in
I have a web application deployed on a jboss server running on a unix
I am running an ASP.NET application. The web server is located on the same
I would like to monitor my program which is running on the web server.
I've installed .NET Framework 3.5 SP1 on web server (Server 2008 Enterprise), so running

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.