Guest User

download_FTP

a guest
Nov 2nd, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. $ftp_server="nuftp.com";
  3. $ftp_user="ftptest@nuftp.com";
  4. $ftp_pass="TiN40L?dK9et";
  5. $remotepath="/virtdocs";
  6. $localpath="E:/Program Files/EasyPHP 3.0/www/tasks/ftp/virtdocs";
  7.  
  8. $ftp_conn=ftp_connect($ftp_server);
  9.  
  10. if(ftp_login($ftp_conn,$ftp_user,$ftp_pass))
  11. {
  12. mkdir($localpath);
  13. ftp_chdir($ftp_conn,$remotepath);
  14. downloadDir($remotepath);
  15. }
  16.  
  17. function downloadDir($path)
  18. {
  19. $items=ftp_nlist($GLOBALS['ftp_conn'],$path);
  20.  
  21. $rawlist=ftp_rawlist($GLOBALS['ftp_conn'],$path);
  22. $merge=array_merge($items,$rawlist);
  23. $i=-1;
  24. foreach($items as $item)
  25. {
  26. $i++;
  27. if(strpos($item,".")===0 && (strrpos($item,".")===1 || strlen($item)==1))
  28. {
  29. //echo $item;
  30. continue;
  31. }
  32. echo "<br>".$rawlist[$i];
  33. $fullpath=$path."/".$item;
  34. //echo "<br>".$fullpath;
  35. $currentlocalpath=str_replace($GLOBALS['remotepath'],$GLOBALS['localpath'],$fullpath);
  36. //echo "<br>".$fullpath."<br>".$currentlocalpath;
  37. if(strpos($rawlist[$i],"d")===0)
  38. {
  39. mkdir($currentlocalpath);
  40. //echo "<br>Dir ".$currentlocalpath;
  41. chdir($currentlocalpath);
  42. ftp_chdir($GLOBALS['ftp_conn'],$fullpath);
  43. downloadDir($fullpath);
  44. ftp_cdup($GLOBALS['ftp_conn']);
  45. //chroot($GLOBALS['localpath']);
  46. }
  47. if(strpos($rawlist[$i],"-")===0)
  48. {
  49. if(ftp_get($GLOBALS['ftp_conn'],$currentlocalpath,$fullpath,FTP_ASCII))
  50. echo "<br>File ".$currentlocalpath;
  51. }
  52. }
  53. }
  54.  
  55. ftp_close($ftp_conn);
  56. ?>
Add Comment
Please, Sign In to add comment