Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. require_once("./config.php");
  10. //require_once("$CFG->dirroot/lib/util/Parser/ParserGI.php");
  11. //
  12. //$Parser = new ParserGI("[[mpso:read#type:invoice#id:404]]");
  13. //
  14. //header('Content-type: application/pdf');
  15. //header('Content-Disposition: inline; filename="downloaded.pdf"');
  16. //
  17. //echo $Parser->aml();
  18.  
  19. dEbug();
  20.  
  21. $sftp_url = "files.iventur.com";
  22. $sftp_username = 'u3306';
  23. $sftp_password = '91(salupro28/';
  24.  
  25. // Make our connection
  26. $connection = ssh2_connect($sftp_url);
  27. print_object($connection);
  28. // Authenticate
  29.  
  30. if (!ssh2_auth_password($connection, $sftp_username, $sftp_password)) {
  31. throw new Exception('Unable to connect.');
  32. }
  33.  
  34. // Create our SFTP resource
  35. if (!$sftp = ssh2_sftp($connection)) {
  36. throw new Exception('Unable to create SFTP connection.');
  37. }
  38.  
  39. /**
  40. * Now that we have our SFTP resource, we can open a directory resource
  41. * to get us a list of files. Here we will use the $sftp resource in
  42. * our address string as I previously mentioned since our ssh2://
  43. * protocol allows it.
  44. */
  45. print_object(intVal($sftp));
  46. $files = array();
  47. $dirHandle = opendir("ssh2.sftp://$sftp/");
  48. /*
  49. // Properly scan through the directory for files, ignoring directory indexes (. & ..)
  50. while (false !== ($file = readdir($dirHandle))) {
  51. if ($file != '.' && $file != '..') {
  52. $files[] = $file;
  53. }
  54. }
  55. */
  56. /**
  57. * Using our newly created list of files, we can go about downloading. We will
  58. * open a remote stream and a local stream and write from one to the other.
  59. * We will use error suppression on the fopen call to suppress warnings from
  60. * not being able to open the file.
  61. */
  62. /*
  63. if (count($files)) {
  64. foreach ($files as $fileName) {
  65. // Remote stream
  66. if (!$remoteStream = @fopen("ssh2.sftp://$sftp/$fileName", 'r')) {
  67. throw new Exception("Unable to open remote file: $fileName");
  68. }
  69.  
  70. // Local stream
  71. if (!$localStream = @fopen("./tmp/$fileName", 'w')) {
  72. throw new Exception("Unable to open local file for writing: /localdir/$fileName");
  73. }
  74.  
  75. // Write from our remote stream to our local stream
  76. $read = 0;
  77. $fileSize = filesize("ssh2.sftp://$sftp/$fileName");
  78. while ($read < $fileSize && ($buffer = fread($remoteStream, $fileSize - $read))) {
  79. // Increase our bytes read
  80. $read += strlen($buffer);
  81.  
  82. // Write to our local file
  83. if (fwrite($localStream, $buffer) === FALSE) {
  84. throw new Exception("Unable to write to local file: /localdir/$fileName");
  85. }
  86. }
  87.  
  88. // Close our streams
  89. fclose($localStream);
  90. fclose($remoteStream);
  91. }
  92. }
  93. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement