Help - Search - Members - Calendar
Full Version: Ftp_get - Downloading Files To Local Drive
Invision Power Services > Community Forums > Community Web Design and Coding
Shmohel
In the admin section of my site, I am attempting to build a script to essentially download all the files from a directory (and in the process I will alter the mysql connection settings). The idea is so that I can easily upload and download to and from my server to my local computer for updating, etc. I have this little bit of code I put together in attempt to do this. However, I am having a problem getting the files from the server to my local drive. Any ideas what I am doing wrong?

CODE
<?
if($_SERVER['REQUEST_URI']=='/index.php?pg=manage'&&$ahop['id']==1){
    $ftp_server="********";
    $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
    $ftp_user='********';
    if (@ftp_login($conn_id, $ftp_user, '*******')) {
        echo "Connected as $ftp_user@$ftp_server<br /><br />\n";
        $mode = ftp_pasv($conn_id, TRUE);
        ftp_chdir($conn_id, "public_html");
        $file_list = ftp_nlist($conn_id, "");
        foreach ($file_list as $file){
            if(is_file($file)&&$file!="google6853f2b77ebc7469.html"&&$file!=".htaccess"){
                $local="C:/ftp".$file;
                if (ftp_get($conn_id, $local, $file, FTP_ASCII)) {
                    echo "Successfully written to ".$file."<br />";
                }
                else {
                    echo "There was a problem\n";
                }
            }
        }
    }
    else {
        echo "Couldn't connect as $ftp_user\n";
    }
    ftp_close($conn_id);
}
else{
echo "Stop snooping. You are not supposed to be able to access this.";
}
?>


When I run this the error I get is:

CODE
Warning: ftp_get(): Error opening C:/ftp in /home/shmohel/public_html/manage.php on line 14


let me know if you ahve any ideas.
Digi
that's because C:/ doesn't exist on the internet or on your server. To get files from you are going to have to use the regular old file downloading options...
Shmohel
Then what is the proper use of ftp_get?
bfarber
Here's the thing...What this script would do is download a file from an ftp server to YOUR WEB SERVER. There isn't a way to do this to download it to your home pc.

You'd need to effectively open your computer up to the internet, put your IP into your script, start an FTP server on your home computer, and FTP it there.....good luck.

I say just use ftp to download the files.
Shmohel
QUOTE(bfarber @ Mar 24 2006, 04:12 PM) *
Here's the thing...What this script would do is download a file from an ftp server to YOUR WEB SERVER. There isn't a way to do this to download it to your home pc.

You'd need to effectively open your computer up to the internet, put your IP into your script, start an FTP server on your home computer, and FTP it there.....good luck.

I say just use ftp to download the files.



Thanks, I appreciate the clarification. What I was trying to do was build a script that would automatically upload and download files for me to and from my PC and search through then to make chagnes. Really just to make the adjustments that are necessary to query the DB on my server versus the one on my local drive.

Guess I will need to find a new solution.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.