Wednesday 17 April 2013

Download All Files from ftp server


       $local_file = "D:/testing/files/";
        $ftp_user_name = "ftp_username";
        $ftp_user_pass = "ftp_pswd";
        
        // set up basic connection
        $conn_id = ftp_connect("122.00.00.001");

        // login with username and password
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        $mode = ftp_pasv($conn_id, TRUE);
        $contents  =  ftp_nlist($conn_id, ".");
        foreach($contents as $file)
        { 
        $local_file=$local_file.$file;
        // try to download $remote_file and save it to $handle
        if (ftp_get($conn_id, $local_file, $file, FTP_ASCII, 0)) {
            echo "successfully written to $local_file\n";
        } else {
        echo "There was a problem while downloading $remote_file to $local_file\n";
        }
        }
        // close the connection and the file handler
        ftp_close($conn_id);
        fclose($handle);
?>

Thursday 6 December 2012

Difference Between Unlink and Unset

unlink()

unlink() is a function for file system handling.
It will simply delete the file in context.  


Example for unlink() :

<?php
$fh = fopen('file.html', 'a');
fwrite($fh, 'Hello world!');
fclose($fh);
unlink('file.html');
?>

Unset ()

Unset () is used to destroy a variable in PHP. In can be used to remove a single variable, multiple variables, or an element from an array. It is phrased as Unset ($remove).
Also Known As: Unset Variable, Destroy Variable.

Example for unset() :

<?php
// remove a single variable
unset($a);

// remove a single element in an array
unset($my_array['element']);

// remove multiple variables
unset($a, $b, $c);
?>