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

  • Home
  • SEARCH
  • 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 7443457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:19:57+00:00 2026-05-29T11:19:57+00:00

I know there are many posts about this issue however I cannot find one

  • 0

I know there are many posts about this issue however I cannot find one single answer on here that describes EXACTLY what I am trying to do and I have been searching for HOURS…so hopefully you all can help me and steer me in the right direction, the main thing I cannot figure out how to do is get the source file and pass that to my update function where I will ftp that file to the remote server…

Basically what I am trying to do is the following:

1) Get a file from my local host (ex. /home/user/public_html/file.php)
2) Upload that file to a remote server of one of my clients (I have all of their FTP information stored in my database and can connect to their server just fine)
3) If the file exists on the remote server, have it over write with the one.

Now, I have tried ftp_get to get the file but that is not what I want to do because I don’t need to re-write or store the same file to the local server…

Here’s what I have so far…

Any help is much appreciated and I do apologize if this is answered some where else I just didn’t see it! 🙂

AS AN UPDATE TO THIS I JUST THOUGHT OF SOMETHING…

Why do I even have to get the local file via ftp? Shouldn’t I just be able to get the local file some other way and pass that to my update function where it will upload that file to the remote server?

update.php

$updater = new updater($accountInfo['ftp_user'],$accountInfo['ftp_pass'],$accountInfo['host']);
$file = "relative/path/to/my/file";
$source = $updater->getFile($file);
$updater->update($source,$file);

my update class

class updater {
var $ftp_user = "";
var $ftp_pass = "";
var $ftp_host = "";

function __construct($user,$pass,$host) {
$this->ftp_user = $user;
$this->ftp_pass = $pass;
$this->ftp_host = $host;    
}



 function getFile($file) {
$curl = curl_init();
$file = fopen($file, 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://domain.com/".$file); #input
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($curl, CURLOPT_FILE, $file); #output
curl_setopt($curl, CURLOPT_USERPWD, "ftpuser:ftppass");
$returnFile = curl_exec($curl);
return $returnFile;
}

function update($source,$file) {
    echo("Source: ".$source."<BR>");
    echo("File: ".$file."<BR>");
$connection = ftp_connect($this->ftp_host);

$login = ftp_login($connection, $this->ftp_user, $this->ftp_pass);

if (!$connection || !$login) { die('Connection attempt failed!'); }

$upload = ftp_put($connection, "/home/".$this->ftp_host."/public_html/".$file, $source, FTP_BINARY);

if (!$upload) { 
echo 'FTP upload failed!'; 
} else {
echo("UPDATED FILE ".$source." SUCCESSFULLY!<BR>"); 
}

ftp_close($connection);     
}
  • 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-29T11:19:58+00:00Added an answer on May 29, 2026 at 11:19 am

    Try this:

        # Declare Files
        $local_file = "/home/user/public_html/file.php";
        $remote_file = "public_html/remote_file.php";
    
        # FTP
        $server = "ftp://ftp.yourhost.com/".$remote_file;
    
        # FTP Credentials
        $ftp_user = "ftp_username";
        $ftp_password = "password";
    
        # Upload File
        $ch = curl_init();
        $ftp_file = fopen($local_file, 'r');
        curl_setopt($ch, CURLOPT_URL, $server);
        curl_setopt($ch, CURLOPT_USERPWD, $ftp_user.":".$ftp_password);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_UPLOAD, 1);
        curl_setopt($ch, CURLOPT_INFILE, $ftp_file);
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($local_file));
        $result = curl_exec($ch);
    

    You can easily put it in a function if this does what you want.

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

Sidebar

Related Questions

I know that there are many posts about this on Stackoverflow, but this one
NOTE: I know there are many questions that talked about that but I'm still
I have read many posts and blogs about rewriting and I know there is
I know that there are many post about hot to use jQuery with mootools,
I know there are many posts about using CRON to run a php file.
I know there are many tutorials out there for getting started in C. However
I know there are already many questions like mine but I found no answer
I know that there are many free and not so free compression libraries out
I know that there are many Delphi database related questions available, but I'm considering
Firstly I know that there are many question and solutions to correct thread marshalling

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.