Guest User

Untitled

a guest
Feb 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $username = "your_username";
  4. $password = "your_pass";
  5. $url = 'your_stp_server_url';
  6.  
  7. // Make our connection
  8. $connection = ssh2_connect($url);
  9.  
  10. // Authenticate
  11. if (!ssh2_auth_password($connection, $username, $password)) throw new Exception('Unable to connect.');
  12.  
  13. // Create our SFTP resource
  14. if (!$sftp = ssh2_sftp($connection)) throw new Exception('Unable to create SFTP connection.');
  15.  
  16. $localDir = '/path/to/your/local/dir';
  17. $remoteDir = '/path/to/your/remote/dir';
  18.  
  19. // download all the files
  20. $files = scandir('ssh2.sftp://' . $sftp . $remoteDir);
  21. if (!empty($files)) {
  22. foreach ($files as $file) {
  23. if ($file != '.' && $file != '..') {
  24. ssh2_scp_recv($connection, "$remoteDir/$file", "$localDir/$file");
  25. }
  26. }
  27. }
  28.  
  29. ?>
Add Comment
Please, Sign In to add comment