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 8120069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:00:23+00:00 2026-06-06T05:00:23+00:00

I have the following script below where I try to mimic a file upload

  • 0

I have the following script below where I try to mimic a file upload via FTP but have changed it for SFTP using phpseclib.

The script echoes out fine until the line:

$upload = $conn_id->put($paths.’/’.$name, $filep,
NET_SFTP_LOCAL_FILE);
echo “upload == “.$upload.”\n”;

where nothing happens or prints out.

here is the full script:

<?
include('Net/SSH2.php');

if(!isset($_POST["submit"])){?>

<form action="upload.php" method="POST" enctype="multipart/form-data">
<table align="center">
<tr>
<td align="right">
Server:
</td>
<td>
<input size="50" type="text" name="server" value="">
</td>
</tr>
<tr>
<td align="right">
Username:
</td>
<td>
<input size="50" type="text" name="user"  value="">
</td>
</tr>
<tr>
<td align="right">
Password:
</td>
<td>
<input size="50" type="text" name="password" value="" >
</td>
</tr>
<tr>
<td align="right">
Path on the server:
</td>
<td>
<input size="50" type="text" name="pathserver" >
</td>
</tr>
<tr>
<td align="right">
Select your file to upload:
</td>
<td>
<input name="userfile" type="file" size="50">
</td>
</tr>
</table>
<table align="center">
<tr>
<td align="center">
<input type="submit" name="submit" value="Upload image" />
</td>
</tr>

</table>
</form>
<?}
else 
{

set_time_limit(300);//for setting 

$paths=$_POST['pathserver'];

echo "paths == ".$paths."\n";

$filep=$_FILES['userfile']['tmp_name'];

echo "filep == ".$filep."\n";

$sftp_server=$_POST['server'];

echo "sftp_server == ".$sftp_server."\n";

$sftp_user_name=$_POST['user'];

echo "sftp_user_name == ".$sftp_user_name."\n";

$sftp_user_pass=$_POST['password'];

echo "sftp_user_pass == ".$sftp_user_pass."\n";

$name=$_FILES['userfile']['name'];

echo "name == ".$name."\n";



// set up a connection to ftp server
$conn_id = new Net_SSH2($sftp_server);

// login with username and password
$login_result = $conn_id->login($sftp_user_name, $sftp_user_pass);

// check connection and login result
if ((!$conn_id) || (!$login_result)) {
       echo "SFTP connection has encountered an error!";
       echo "Attempted to connect to $sftp_server for user $sftp_user_name....";
       exit;
   } else {
       echo "Connected to $sftp_server, for user $sftp_user_name".".....";
   }


echo "HERE "."\n";
// upload the file to the path specified


$upload = $conn_id->put($paths.'/'.$name, $filep, NET_SFTP_LOCAL_FILE);
echo "upload == ".$upload."\n";

// check the upload status
if (!$upload) {
       echo "SFTP upload has encountered an error!";
   } else {
       echo "Uploaded file with name $name to $sftp_server ";
   }

// close the FTP connection
ftp_close($conn_id);    

}
?>
  • 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-06T05:00:25+00:00Added an answer on June 6, 2026 at 5:00 am

    Which library is NET/ssh2.php? Looks like http://phpseclib.sourceforge.net?

    You’re mixing their SSH2 and SFTP libraries. Taken directly from their manual, the code you want is:

    <?php
    include('Net/SFTP.php');
    
    $sftp = new Net_SFTP('www.domain.tld');
    if (!$sftp->login('username', 'password')) {
        exit('Login Failed');
    }
    
    echo $sftp->pwd() . "\r\n";
    $sftp->put('filename.ext', 'hello, world!');
    print_r($sftp->nlist());
    ?>
    

    So just change the $data in the “put” function to be the filename, and adding the mode as you’ve done in your code.

    An alternative would be the PECL functions provided by PHP. These have sftp functions “built in”. Example code is http://www.php.net/manual/en/function.ssh2-sftp.php and if it still doesn’t work, we’ll be better placed to help debug as we can all access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below script running and the following logcat report as at the
I have the following script that recieves an xml file and reads it with
I have the following script to validate my form. It is working fine but
I have made the following script to upload a csv and import it into
The following script below is not running in IE7 but works perfectly fine in
I have written the following script below - I am not quite happy with
I have following small script to preview some text before submitting it to store
I have the following script that outputs a shipping amount number depending on what
I have the following script that call a http handler. It calls the http
The following is a MYSQL script: I have the following script to put a

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.