Advertisement
Mooash

PHP FTP Form

Apr 9th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2. $fastdl_server = '#####';
  3. $fastdl_user = '#####';
  4. $fastdl_pass = '#####';
  5.  
  6. // Set up basic connection
  7. $fastdl_id = ftp_connect($fastdl_server);
  8.  
  9. // Login with username and password
  10. $fastdl_login_result = ftp_login($fastdl_id, $fastdl_user, $fastdl_pass);
  11.  
  12. // Get the file list for /
  13. $fastdl_buff = ftp_nlist($fastdl_id, '/not real path ive copied it out/inversion/fastdl/cache/garrysmod/cache');
  14.  
  15. // Create the date array
  16. $fastdl_date = array((count($fastdl_buff) - 1));
  17.  
  18. // Put the dates in the date array
  19. for($i =0; $i < count($fastdl_buff); $i++){
  20.     $buff = ftp_mdtm($fastdl_id, '/not real path ive copied it out/inversion/fastdl/cache/cache/'.$fastdl_buff[$i]);
  21.     $fastdl_date[$i] = $buff;
  22. }
  23.  
  24. // Finds newest date and puts the corrosdponding array number into variable
  25. $fastdl_newest_date = array_search(max($fastdl_date),$fastdl_date);
  26. $fastdl_newest_file = $fastdl_buff[$fastdl_newest_date];
  27.  
  28. // Checks if the file exists locally.
  29. if(file_exists('/not real path ive copied it out/inversion/fastdl/cache/'.$fastdl_newest_file)){ echo 'Cache is fine!'; }
  30.  
  31. // Clears out the local folder. FTPs newest file down. Clears out the FTP dir.
  32. else{
  33.     for($i =0; $i < count($fastdl_buff); $i++){
  34.         if($i != $fastdl_newest_date){ftp_delete($fastdl_id,'/not real path/garrysmod/cache/'.$fastdl_buff[$i]);}
  35.         }
  36.     echo 'Cleared out the FTP apart from newest file.<br/>';
  37.     ftp_get($fastdl_id, '/not real path ive copied it out/inversion/fastdl/cache/'.$fastdl_newest_file, '/not real path/garrysmod/cache/'.$fastdl_newest_file, FTP_BINARY);
  38.     echo 'Updated the cache!';
  39.     }
  40.    
  41.  
  42. // close the connection
  43. ftp_close($fastdl_id);
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement