Asheeown Posted August 6, 2009 Share Posted August 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 ctrl+c ctrl+v --- ssh2_scp_send($con, "/tmp/source.dat", "/tmp/dest.dat", 0644); http://www.php.net/manual/en/function.ssh2-scp-send.php sources used: http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ Quote Link to comment Share on other sites More sharing options...
Asheeown Posted August 6, 2009 Author Share Posted August 6, 2009 Warning: ssh2_scp_send() [function.ssh2-scp-send]: Failure creating remote file in /home/Migrate/htdocs/test.php on line 167 I tried the connection with both server connections. Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 are you sure you've got write permissions to the directory you're shoving the file into? Quote Link to comment Share on other sites More sharing options...
Asheeown Posted August 6, 2009 Author Share Posted August 6, 2009 I'm connecting as root for development purposes, so yes. Is there a way I can create the file first? Maybe that will give it the shove it needs Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 I#m guessing you also have to use receive...: http://php.oregonstate.edu/manual/en/function.ssh2-scp-recv.php If when trying to use this function you get "Warning: ssh2_scp_send(): Failure creating remote file," then try using $data = file_get_contents("ssh2.sftp://$sftp/path/to/file"); Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 IDK you could try sending MJ`s favorite linux command: touch /tmp/file.ext Quote Link to comment Share on other sites More sharing options...
Asheeown Posted August 6, 2009 Author Share Posted August 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 cool cool glad you got it working Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.