ftp copy file to localhost

Posted on 2012-09-20
Last Modified: 2012-09-20
i have successfully connected
there is one file in one folder

want to copy that file to localhost



//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';
  echo 'what happened';

//Close FTP connection

Open in new window

php_rawlist only shows filenames
Question by:rgb192
    LVL 36

    Expert Comment

    by:Loganathan Natarajan
    You can very well use, ftp_get() function to download the files, ref.
    LVL 36

    Accepted Solution

    try with this script, replace the server details with local path etc.,

            $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";
                echo "There was a problem in the ftp connection \n";

    Open in new window


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now