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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:12:54+00:00 2026-06-07T12:12:54+00:00

While trying to list the files present in a remote sftp location using php,

  • 0

While trying to list the files present in a remote sftp location using php, I get this error:

Error 324 (net::ERR_EMPTY_RESPONSE):

The server closed the connection without sending any data. On my another lamp server the same code works fine. Please point where I am missing something if you can help please. Thanks in advance.

function listBuildFiles() {

global $sftp_host, $sftp_username, $sftp_password, $sftp_path;
$connection = ssh2_connect($sftp_host);
// Authenticate
if (!ssh2_auth_password($connection, $sftp_username, $sftp_password)) {
    throw new Exception('Unable to connect.');
}

// Create our SFTP resource
if (!$sftp = ssh2_sftp($connection)) {
    throw new Exception('Unable to create SFTP connection.');
}

/**
 * Now that we have our SFTP resource, we can open a directory resource
 * to get us a list of files. Here we will use the $sftp resource in
 * our address string as I previously mentioned since our ssh2://
 * protocol allows it.
 */
$files = array();
$dirHandle = opendir("ssh2.sftp://$sftp$sftp_path");
    $i=0;
// Properly scan through the directory for files, ignoring directory indexes (. & ..)
while (false !== ($file = readdir($dirHandle))) {
    if ($file != '.' && $file != '..') {
        $files[$i] = $file;
        $i++;
    }
}

echo '<select name="buildName">';
echo '<option>Please Select a build</option>';
foreach ($files as $filename) {
      echo "<option value=\"$filename\">$filename</option>";
    }
echo '</select>';
ssh2_exec($connection, "exit");

Thanks,
Ujjwal

  • 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-07T12:12:56+00:00Added an answer on June 7, 2026 at 12:12 pm

    With phpseclib, a pure PHP SFTP implementation, you can see the full logs of what’s going on. Example:

    <?php
    include('Net/SFTP.php');
    
    define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
    
    $sftp = new Net_SFTP('www.domain.tld');
    if (!$sftp->login('username', 'password')) {
        exit('Login Failed');
    }
    
    // puts a three-byte file named filename.remote on the SFTP server
    $sftp->put('filename.remote', 'xxx');
    
    echo $ssh->getLog();
    print_r($ssh->getErrors());
    ?>
    

    The developer of phpseclib is pretty proactive about providing support too so if you can’t figure it out from the logs or error messages (s)he probably can.

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

Sidebar

Related Questions

I was trying to get a list of files under a directory using: val
I am trying to list all the files included in folder using following php
While trying to host the CLR, I keep getting this: error C2440: 'function' :
I'm trying to loop through a list of files to get the path and
I'm trying to fetch list of files using a method that apparently works well
While trying to compile a 64 bit linux kernel using gcc, I see the
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,
I'm trying to use MSBuild to read in a list of files from a
While trying to zip an archive using the java.util.zip I ran into a lot
The Situation : I am trying to display a list of files from my

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.