Dynadot โ€” .com Registration $8.99

Php updater script

Spaceship Spaceship
Watch

FrozenNova

Established Member
Impact
1
Hi,

Looking for a simple php script that connects to an ftp server downloads "x.zip" and extracts it to the current folder, as I have begun running a fairly large proxy network and need a faster way of deploying updates that manually updating each site via ftp.

Willing to donate a few NP$s and rep.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
The following should do what you want. It needs FTP and ZIP support compiled into your PHP installation.

PHP:
<?php

////////////////////////////////////////////////////////////
// START OF CONFIGURATION
////////////////////////////////////////////////////////////


// Set to the directory to extract archive to
$extractTo = '/home/mysite/public_html/folder/';

// Set remote FTP server
$ftp_server = 'ftp.somedomain.com';

// FTP login details:
$ftp_user_name = 'ftpuser';
$ftp_user_pass = 'ftppass';

// Name of the zip file
$filename = 'x.zip';

////////////////////////////////////////////////////////////
// END OF CONFIGURATION
////////////////////////////////////////////////////////////

// Connect to the FTP server
$ftp_id = ftp_connect($ftp_server);

// Login to FTP server
$login_result = ftp_login($ftp_id, $ftp_user_name, $ftp_user_pass);

// Download file from the FTP server
if (ftp_get($ftp_id, $filename, $filename, FTP_BINARY))
{
    $zip = new ZipArchive;
    
    // Open the zip file
    if ($zip->open($filename))
    {
        // Extract the zip file
        $zip->extractTo($extractTo);
        
        // Close the ZIP file
        $zip->close();
        
        echo "Unzipped OK";
    }
    else
    {
        echo "Unable to unzip $filename";
    }
}
else
{
    echo "Unable to download $filename from FTP server\n";
}

// Close the FTP connection
ftp_close($ftp_id);

// Remove the zip file
@unlink($filename);

?>
 
1
•••
recieving the following error:
Code:
Warning: ftp_get(/proxy.zip) [function.ftp-get]: failed to open stream: Permission denied in /home/anime/public_html/update.php on line 32

Warning: ftp_get() [function.ftp-get]: Error opening /proxy.zip in /home/anime/public_html/update.php on line 32
Unable to download /proxy.zip from FTP server

The update.php file has been chmodded to "777" and cannot see why this will not work.

Regards
 
0
•••
I guess you have this:

PHP:
$filename = '/proxy.zip';

Change it to this (without leading slash):

PHP:
$filename = 'proxy.zip';

Also I suggest you change the script permission to 755 (at the most). 777 could pose a security risk (depending on your server configuration).
 
0
•••
I've tried it with and without the trailing slash, I have also rewrote the script with no avail, I can find the script I used for this before.
 
0
•••
What error do you get using it without the leading slash?

Try adding the following before the ftp_get to list the directory contents:

PHP:
var_dump(ftp_nlist($ftp_id, "."));

and check that proxy.zip is present.
 
Last edited:
0
•••
proxy.zip is definatly present error can be seen at the-anime.net/update.php
 
0
•••
I now think the message is caused because your PHP script does not have permission to save the file. You could check this by chmod 777 on your public_html directory, then trying the script again. I would not recommend this as a long term solution, since it could pose a security risk.
 
0
•••
Ive been playing and found a better solution I'm now running it through Shell which has solved the first problem and also means I don't have to visit each update page to deploy updates
 
0
•••
If you have shell access, you could run the PHP script from the shell:

$ php update.php
 
0
•••
yea thats what im doing now but i wrote a bash script to make it even easier its just a case of typing /update now :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back