Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:05:17+00:00 2026-06-16T03:05:17+00:00

I’m trying to SFTP a HTML file made on the fly(using file put contents)

  • 0

I’m trying to SFTP a HTML file made on the fly(using file put contents) and the shh2 library.

Here’s what I’ve got so far, apache reports that it can’t be sent as the file doesn’t exist on the local disk:

$pageBody = '<body>
    <div id="canvas_container">
        <canvas id="designer_canvas" width="430" height="415">
        </canvas>
    </div>
<div style="display:none" id="share_design_details">
<li>'.$mc1.'</li><li>'.$mc1.'</li><li>'.$mc2.'</li><li>'.$sp.'</li><li>'.$p.'</li><li>'.$c.'</li></div>

<div id="test">This design is called : '.$designName.'</div></body>' ; 


$newFile = file_put_contents('newfile.html',$pageBody);
$connection = ssh2_connect('myhost.com', 22);
ssh2_auth_password($connection, 'myuser', 'mypass');

$sftp = ssh2_sftp($connection);
ssh2_scp_send($connection, $newFile, $newFile, 0644);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:05:18+00:00Added an answer on June 16, 2026 at 3:05 am

    The ssh2_scp_send() function requires the file path for the local and remote files.

    http://php.net/manual/en/function.ssh2-scp-send.php

    The file_put_contents() function returns the number of bytes written to the file, not the file path.

    http://php.net/manual/en/function.file-put-contents.php

    Therefore, your ssh2_scp_send() should read something as follows where the target directory on your target server is /tmp:

    ssh2_scp_send($connection, 'newfile.html', '/tmp/newfile.html', 0644);
    

    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.

    I would simply delete the file after sending using the unlink() function.

    http://php.net/manual/en/function.unlink.php

    So your complete logic would be as follows:

    //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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.