Jump to content

[SOLVED] SSH2 Copy File


Asheeown

Recommended Posts

I need to copy a file from one remote server to another remote server with valid ssh2 connections that are already made.  Do I have to use fopen to create the file then pull the content inside the file I want to copy and write it into the new one?  Or is there an easier way to go about this?

Link to comment
Share on other sites

Hey Mar, sorry I didn't post back last night but I got it working.

 

<?php
$BashProfileSource = file_get_contents("ssh2.sftp://".$Source['sftp']."".$h[1]."/.bash_profile");
$BashProfileStream = fopen("ssh2.sftp://".$Destination['sftp']."".$h[1]."/.bash_profile", 'w');
if($BashProfileDest = fwrite($BashProfileStream, $BashProfileSource)) echo "<font color=\"green\">User ".$h['0'].": Created bash profile file</font><br>";
fclose($BashProfileStream);
ssh2_exec($Destination['Connection'], "chmod +x ".$h[1]."/.bash_profile");
?>

 

It's copying the .bash files for a user migration in linux :)

 

Thanks for the help the file_get_contents method worked the best.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.