Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $url = "<URL></URL>";
- $user = "<USERNAME></USERNAME>";
- $pass = "<PASSWORD></PASSWORD>";
- $directory = "Inbox";
- echo "SDDSDS";
- const DS = "/";
- $sshResource = ssh2_connect($url, 22);
- if (!$sshResource) {
- echo 'Connection failed!';
- exit();
- }
- if(!ssh2_auth_password($sshResource, $user, $pass)) {
- echo 'Authentication failed!';
- exit();
- }
- $sftpResource = ssh2_sftp($sshResource);
- if (!$sftpResource){
- echo 'Connection to sftp failed!';
- return false;
- }
- $source = "<some_file_path_locally>";
- try {
- $name = array_pop(explode("/", $source));
- $remoteFileStream = fopen("ssh2.sftp://".$sftpResource . DS . $directory . DS . $name, 'w+');
- if(fwrite($remoteFileStream, file_get_contents($source))) {
- fclose($remoteFileStream);
- echo "file pushed";
- }
- return false;
- }
- catch (Exception $e) {
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement