Guest User

Untitled

a guest
May 12th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2.  
  3. /* the host name or ip to download from */
  4. $host = '192.168.1.2';
  5. /* the absolute path on the host name */
  6. $abspath = '/full/path/to/download';
  7. /* username for host */
  8. $user = 'cosmo';
  9. /* password for user on host */
  10. $pass = 'cosmo';
  11. /* trg file*/
  12. $trg = 'test.dat';
  13.  
  14. /* get curl instance */
  15. $curl = curl_init();
  16. /* set url of file to download */
  17. $url = 'scp://' . $host . ':' . $abspath;
  18. curl_setopt($curl, CURLOPT_URL, $url);
  19. /* set credentials */
  20. curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $pass);
  21. /* set target file */
  22. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  23. $fh = fopen($trg, 'w') or die('failed to open ' . $trg . ' for writing!');
  24. curl_setopt($curl, CURLOPT_FILE, $fh);
  25. /* start */
  26. echo "<p>Output of curl_exec</p><pre>";
  27. curl_exec($curl) or die(curl_error($curl));
  28. /* close the curl instance */
  29. echo "</pre>";
  30. curl_close($curl);
  31. fclose($fh);
  32.  
  33. echo "<p>File should now be successfully downloaded from $url to $trg:</p>";
  34. echo '<pre>' . file_get_contents($trg) . '</pre>';
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment