Guest User

Untitled

a guest
Jan 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. $SSH_CONNECTION= ssh2_connect('xx.xxx.xx.xx', xx);
  2. ssh2_auth_password($SSH_CONNECTION, 'xxxxxxx', 'xxxxxxxxxxxxx');
  3.  
  4. function scanFilesystem($dir) {
  5. $tempArray = array();
  6. $handle = opendir($dir);
  7. // List all the files
  8. while (false !== ($file = readdir($handle))) {
  9. if (substr("$file", 0, 1) != "."){
  10. if(is_dir($file)){
  11. $tempArray[$file]=scanFilesystem("$dir/$file");
  12. } else {
  13. $tempArray[]=$file;
  14. }
  15. }
  16. }
  17. closedir($handle);
  18. return $tempArray;
  19. }
  20.  
  21.  
  22. $sftp = ssh2_sftp($SSH_CONNECTION);
  23.  
  24. //code to get listing of all OUTGOING files
  25. $dir = "ssh2.sftp://$sftp//home/user/mail/websiteaddress.com.au/janedoe";
  26. $outgoing = scanFilesystem($dir);
  27. sort($outgoing);
  28. print_r($outgoing);
  29.  
  30. array(4) {
  31. [0]=> string(3) "cur"
  32. [1]=> string(11) "maildirsize"
  33. [2]=> string(3) "new"
  34. [3]=> string(3) "tmp"
  35. }
  36.  
  37. function scanFilesystem($dir) {
  38. $tempArray = array();
  39. $tempArray['total_size'] = 0;
  40. $handle = opendir($dir);
  41. // List all the files
  42. while (false !== ($file = readdir($handle))) {
  43. if (substr("$file", 0, 1) != "."){
  44. if(is_dir($file)){
  45. $tempArray[$file]=scanFilesystem("$dir/$file");
  46. $tempArray['total_size'] += $tempArray[$file]['total_size'];
  47. } else {
  48. $tempArray[]=$file;
  49. $tempArray['total_size'] += filesize("$dir/$file");
  50. }
  51. }
  52. }
  53. closedir($handle);
  54. return $tempArray;
  55. }
Add Comment
Please, Sign In to add comment