Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <?php
  2. $url = "<URL></URL>";
  3. $user = "<USERNAME></USERNAME>";
  4. $pass = "<PASSWORD></PASSWORD>";
  5.  
  6. $directory = "Inbox";
  7. echo "SDDSDS";
  8. const DS = "/";
  9. $sshResource = ssh2_connect($url, 22);
  10.  
  11. if (!$sshResource) {
  12. echo 'Connection failed!';
  13. exit();
  14. }
  15.  
  16. if(!ssh2_auth_password($sshResource, $user, $pass)) {
  17. echo 'Authentication failed!';
  18. exit();
  19. }
  20.  
  21. $sftpResource = ssh2_sftp($sshResource);
  22. if (!$sftpResource){
  23. echo 'Connection to sftp failed!';
  24. return false;
  25. }
  26. $source = "<some_file_path_locally>";
  27. try {
  28. $name = array_pop(explode("/", $source));
  29. $remoteFileStream = fopen("ssh2.sftp://".$sftpResource . DS . $directory . DS . $name, 'w+');
  30.  
  31. if(fwrite($remoteFileStream, file_get_contents($source))) {
  32. fclose($remoteFileStream);
  33. echo "file pushed";
  34. }
  35. return false;
  36. }
  37. catch (Exception $e) {
  38. echo $e->getMessage();
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement