Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. <?php
  2. // file on the web server
  3. $local_file = "log.txt";
  4.  
  5. // The delimeter is the character used to split a string
  6. $delimeter = '\n';
  7.  
  8. // ftp server
  9. $ftp_server = "ftp.example.com";
  10.  
  11. // ftp username
  12. $ftp_username = 'username';
  13.  
  14. // ftp password
  15. $ftp_userpass = 'pass';
  16.  
  17. // file on the ftp server
  18. $server_file = "log.txt";
  19.  
  20. if(file_exists($local_file))
  21. {
  22.     // time difference between now and file
  23.     $time_diff = time() - filemtime($local_file);
  24.    
  25.     // 86400 is one day in seconds
  26.     if($time_diff >= 86400)
  27.     {
  28.         // connect to FTP server
  29.         $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  30.  
  31.         // Login to the server
  32.         $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
  33.  
  34.         // download server file
  35.         if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
  36.         {
  37.             // successfully written to file
  38.         }
  39.         else
  40.         {
  41.             echo "Error downloading $server_file.";
  42.         }
  43.  
  44.         // close connection
  45.         ftp_close($ftp_conn);
  46.     }
  47.    
  48.    
  49. }
  50. else
  51. {
  52.     // connect to FTP server
  53.     $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  54.  
  55.     // Login to the server
  56.     $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
  57.  
  58.     // download server file
  59.     if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
  60.     {
  61.         // successfully written to file
  62.     }
  63.     else
  64.     {
  65.         echo "Error downloading $server_file.";
  66.     }
  67.  
  68.     // close connection
  69.     ftp_close($ftp_conn);
  70. }
  71.  
  72. $data = file($local_file); 
  73.    
  74. // Loop through the array and output the data to the screen
  75. foreach($data as $value)
  76. {
  77.     // Echo tells the script to output it to the screen
  78.     echo '<p>'.$value.'</p>';
  79. }
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement