I use a command like this on my Mac to scp to my remote server (in a .sh file—it must be done automatically).
scp -i my_key.pem index.html ubuntu@<ip>:~/public/index.html;
Now I have to do the same thing from a Windows machine and figured I would just write it in php instead of using bash so that the code is the same on Windows and Mac (our app runs a local server too that already uses php scripts, it's complicated). I've looked at a few examples but can't find my exact solution. Also, to be honest I don't know much about private/public keys and I want to be careful.
I've got something like this. I don't know what to do for the key.
$hostname = '21.232.foo.bar';
$sourceFile = 'index.html';
$targetFile = '~/public/indexx.html';
// SSH Key File — I'm guessing this should be private, not public
private $ssh_auth_priv = '~/.ec2/my_key.pem';
$connection = ssh2_connect($hostname, 22);
ssh2_scp_send($connection, $sourceFile, $targetFile, 0777);
Also, if I'm trying to do something stupid and there is a much easier way, please let me know. Thanks for your help.
~~ UPDATE
My code now looks as follows and I'm getting an error Warning: ssh2_scp_send(): Failure creating remote file: failed to send file
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$hostname = '13.124.foo.bar';
$sourceFile = 'foo.txt';
$targetFile = '~/public2/foo.txt';
$connection = ssh2_connect($hostname, 22);
ssh2_auth_pubkey_file(
$connection,
'ubuntu',
'~/.ec2/id_rsa.pub',
'~/.ec2/bh.pem'
);
ssh2_scp_send($connection, $sourceFile, $targetFile, 0644);
?>
</body>
</html>
That's being hosted on my localhost:8000