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? Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/ 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/ Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891891 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. Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891894 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? Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891895 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 Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891896 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"); Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891898 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 Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-891899 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. Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-892016 Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 cool cool glad you got it working Link to comment https://forums.phpfreaks.com/topic/169044-solved-ssh2-copy-file/#findComment-892044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.