Advertisement
Guest User

Untitled

a guest
Dec 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. function ftp_sync ($dir) {
  2.  
  3. global $conn_id;
  4.  
  5. if ($dir != ".") {
  6. if (ftp_chdir($conn_id, $dir) == false) {
  7. echo ("Change Dir Failed: $dir<BR>rn");
  8. return;
  9. }
  10. if (!(is_dir($dir)))
  11. mkdir($dir);
  12. chdir ($dir);
  13. }
  14.  
  15. $contents = ftp_nlist($conn_id, ".");
  16. foreach ($contents as $file) {
  17.  
  18. if ($file == '.' || $file == '..')
  19. continue;
  20.  
  21. if (@ftp_chdir($conn_id, $file)) {
  22. ftp_chdir ($conn_id, "..");
  23. ftp_sync ($file);
  24. }
  25. else
  26. ftp_get($conn_id, $file, $file, FTP_BINARY);
  27. }
  28.  
  29. ftp_chdir ($conn_id, "..");
  30. chdir ("..");
  31.  
  32. }
  33.  
  34. ini_set('max_execution_time', 0);
  35. set_time_limit(0);
  36.  
  37. header("Location: " . __FILE__ . "?file=$file");
  38.  
  39. function ftp_sync ($dir) {
  40.  
  41. global $conn_id;
  42.  
  43. if( isset($_GET['cd']) ) {
  44. $dir = $_GET['cd'];
  45. }
  46.  
  47. if ($dir != ".") {
  48. if (ftp_chdir($conn_id, $dir) == false) {
  49. echo ("Change Dir Failed: $dir<BR>rn");
  50. return;
  51. }
  52. if (!(is_dir($dir)))
  53. mkdir($dir);
  54. chdir ($dir);
  55. }
  56.  
  57. $contents = ftp_nlist($conn_id, ".");
  58. foreach ($contents as $file) {
  59.  
  60. if ($file == '.' || $file == '..')
  61. continue;
  62.  
  63. if (@ftp_chdir($conn_id, $file)) {
  64. ftp_chdir ($conn_id, "..");
  65. ftp_sync ($file);
  66. header("refresh:0.5;url=" . "ftp.php" . "?file=$file&cd=" . ftp_pwd($conn_id));
  67. die();
  68. }
  69. else {
  70. ftp_get($conn_id, $file, $file, FTP_BINARY);
  71. }
  72. }
  73.  
  74. ftp_chdir ($conn_id, "..");
  75. chdir ("..");
  76.  
  77. }
  78.  
  79. <?php
  80. error_reporting(0);
  81. set_time_limit(0);
  82. session_start();
  83.  
  84. // SETTINGS
  85. $ftp_hostname = "";
  86. $ftp_port = 21;
  87. $ftp_username = "";
  88. $ftp_password = "";
  89. $where_to_download = "."; // Without the last slash!
  90. // ---------------------
  91.  
  92. // NOTE: If you want to end the current session; go to http://example.com/filename.php?end
  93.  
  94. if( isset($_GET['end']) ) {
  95. session_unset();
  96. session_destroy();
  97. die("Successfully ended the session.");
  98. }
  99.  
  100. include("ftpcrawler.php");
  101. $ftpcrawler = new ftpcrawler;
  102. $ftpcrawler->server = "ftp://$ftp_username:$ftp_password@$ftp_hostname:$ftp_port/";
  103. if( !isset($_SESSION['array']) ) {
  104. $_SESSION['array'] = $ftpcrawler->crawl();
  105. }
  106. if( empty($_SESSION['array']) ) {
  107. echo "Finished downloading everything , or theres no files to download.";
  108. session_unset();
  109. session_destroy();
  110. die();
  111. }
  112. foreach($_SESSION['array'] as $item) {
  113. if( $item['type'] == "file" ) {
  114. $ITEM_DIRECTORY = str_replace($item['name'], "", $item['path']);
  115. }
  116. if( $item['type'] == "directory" ) {
  117. $ITEM_DIRECTORY = $item['path'];
  118. }
  119. if (!file_exists($where_to_download . $ITEM_DIRECTORY) && !is_dir($where_to_download . $ITEM_DIRECTORY)) {
  120. mkdir($where_to_download . $ITEM_DIRECTORY, 0777, TRUE);
  121. }
  122. if( $item['type'] == "file" ) {
  123. $data = @file_get_contents("ftp://$ftp_username:$ftp_password@$ftp_hostname:$ftp_port" . $item['path']);
  124. file_put_contents($where_to_download . $item['path'], $data);
  125. }
  126. unset($_SESSION['array'][$item['path']]);
  127. echo "Downloaded/Created Folder " . $item['path'] . " !";
  128. header( "refresh:0.2;url=" . basename(__FILE__) );
  129. die();
  130. }
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement