Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- require_once("./config.php");
- //require_once("$CFG->dirroot/lib/util/Parser/ParserGI.php");
- //
- //$Parser = new ParserGI("[[mpso:read#type:invoice#id:404]]");
- //
- //header('Content-type: application/pdf');
- //header('Content-Disposition: inline; filename="downloaded.pdf"');
- //
- //echo $Parser->aml();
- dEbug();
- $sftp_url = "files.iventur.com";
- $sftp_username = 'u3306';
- $sftp_password = '91(salupro28/';
- // Make our connection
- $connection = ssh2_connect($sftp_url);
- print_object($connection);
- // Authenticate
- if (!ssh2_auth_password($connection, $sftp_username, $sftp_password)) {
- throw new Exception('Unable to connect.');
- }
- // Create our SFTP resource
- if (!$sftp = ssh2_sftp($connection)) {
- throw new Exception('Unable to create SFTP connection.');
- }
- /**
- * Now that we have our SFTP resource, we can open a directory resource
- * to get us a list of files. Here we will use the $sftp resource in
- * our address string as I previously mentioned since our ssh2://
- * protocol allows it.
- */
- print_object(intVal($sftp));
- $files = array();
- $dirHandle = opendir("ssh2.sftp://$sftp/");
- /*
- // Properly scan through the directory for files, ignoring directory indexes (. & ..)
- while (false !== ($file = readdir($dirHandle))) {
- if ($file != '.' && $file != '..') {
- $files[] = $file;
- }
- }
- */
- /**
- * Using our newly created list of files, we can go about downloading. We will
- * open a remote stream and a local stream and write from one to the other.
- * We will use error suppression on the fopen call to suppress warnings from
- * not being able to open the file.
- */
- /*
- if (count($files)) {
- foreach ($files as $fileName) {
- // Remote stream
- if (!$remoteStream = @fopen("ssh2.sftp://$sftp/$fileName", 'r')) {
- throw new Exception("Unable to open remote file: $fileName");
- }
- // Local stream
- if (!$localStream = @fopen("./tmp/$fileName", 'w')) {
- throw new Exception("Unable to open local file for writing: /localdir/$fileName");
- }
- // Write from our remote stream to our local stream
- $read = 0;
- $fileSize = filesize("ssh2.sftp://$sftp/$fileName");
- while ($read < $fileSize && ($buffer = fread($remoteStream, $fileSize - $read))) {
- // Increase our bytes read
- $read += strlen($buffer);
- // Write to our local file
- if (fwrite($localStream, $buffer) === FALSE) {
- throw new Exception("Unable to write to local file: /localdir/$fileName");
- }
- }
- // Close our streams
- fclose($localStream);
- fclose($remoteStream);
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement