Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <strong>ssh2_scp_send()</strong> function requires the file path for the local and remote files.</p> <p><a href="http://php.net/manual/en/function.ssh2-scp-send.php" rel="nofollow">http://php.net/manual/en/function.ssh2-scp-send.php</a></p> <p>The <strong>file_put_contents()</strong> function returns the number of bytes written to the file, not the file path.</p> <p><a href="http://php.net/manual/en/function.file-put-contents.php" rel="nofollow">http://php.net/manual/en/function.file-put-contents.php</a></p> <p>Therefore, your <strong>ssh2_scp_send()</strong> should read something as follows where the target directory on your target server is <em>/tmp</em>:</p> <pre><code>ssh2_scp_send($connection, 'newfile.html', '/tmp/newfile.html', 0644); </code></pre> <p>I don't think it is possible to upload a file that does not exist yet as you would essentially be writing directly to the target server as opposed to uploading a file.</p> <p>I would simply delete the file after sending using the <strong>unlink()</strong> function.</p> <p><a href="http://php.net/manual/en/function.unlink.php" rel="nofollow">http://php.net/manual/en/function.unlink.php</a></p> <p>So your complete logic would be as follows:</p> <pre><code>//Define content $pageBody = 'CONTENT HERE'; //Create the file $newFile = file_put_contents('temp.html', $pageBody); //Connect to SFTP host $connection = ssh2_connect('myhost.com', 22); ssh2_auth_password($connection, 'myuser', 'mypass'); $sftp = ssh2_sftp($connection); //Send the file ssh2_scp_send($connection, 'temp.html', '/tmp/temp.html', 0644); //Delete the local file unlink('temp.html); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload