Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

ftp copy file to localhost

i have successfully connected
there is one file in one folder

want to copy that file to localhost

<?php
error_reporting(E_ALL);

$host='';
$user='';
$password='';

//Connect to the FTP server
$ftpstream = ftp_connect($host);

//Login to the FTP server
$login = ftp_login($ftpstream, $user, $password);
if($login) {
  //We are now connected to FTP server.
  echo 'connected';
}else{
  echo 'what happened';
}

//Close FTP connection
ftp_close($ftpstream);

Open in new window



php_rawlist only shows filenames
0
rgb192
Asked:
rgb192
  • 2
1 Solution
 
Loganathan NatarajanLAMP DeveloperCommented:
You can very well use, ftp_get() function to download the files, ref. http://php.net/manual/en/function.ftp-get.php
0
 
Loganathan NatarajanLAMP DeveloperCommented:
try with this script, replace the server details with local path etc.,

<?php
		error_reporting(E_ALL);

       
        $folder_path = "YOUR FOLDER PATH";
        $local_file = "LOCAL FILE PATH";
        $server_file = "SERVER FILE PATH";

        $ftp_server = "IP ADDRESS"; // Address of FTP server.
        $ftp_user_name = "USERNAME"; // Username
        $ftp_user_pass = "PASSWORD"; // Password
              
        $conn_id = ftp_connect($ftp_server);

        // login with username and password
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

        // try to download $server_file and save to $local_file
        if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) 
		{
            echo "Successfully written to $local_file\n";
        } 
		else 
		{
            echo "There was a problem in the ftp connection \n";
        }
        
        ftp_close($conn_id);
?>
 

Open in new window

0
 
rgb192Author Commented:
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now