Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // file on the web server
- $local_file = "log.txt";
- // The delimeter is the character used to split a string
- $delimeter = '\n';
- // ftp server
- $ftp_server = "ftp.example.com";
- // ftp username
- $ftp_username = 'username';
- // ftp password
- $ftp_userpass = 'pass';
- // file on the ftp server
- $server_file = "log.txt";
- if(file_exists($local_file))
- {
- // time difference between now and file
- $time_diff = time() - filemtime($local_file);
- // 86400 is one day in seconds
- if($time_diff >= 86400)
- {
- // connect to FTP server
- $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
- // Login to the server
- $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
- // download server file
- if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
- {
- // successfully written to file
- }
- else
- {
- echo "Error downloading $server_file.";
- }
- // close connection
- ftp_close($ftp_conn);
- }
- }
- else
- {
- // connect to FTP server
- $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
- // Login to the server
- $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
- // download server file
- if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
- {
- // successfully written to file
- }
- else
- {
- echo "Error downloading $server_file.";
- }
- // close connection
- ftp_close($ftp_conn);
- }
- $data = file($local_file);
- // Loop through the array and output the data to the screen
- foreach($data as $value)
- {
- // Echo tells the script to output it to the screen
- echo '<p>'.$value.'</p>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement