Faye D.
Faye D.

Reputation: 732

ftp_ssl_connect and ftp_nlist

I need to connect to a remote system to get some files. The specs of the remote system mention that:

The Protocol required is SFTP - SSH File Transfer Protocol The Port Number is 22

Before anything else, I used my FTP client app to try to log into the new server using the given credentials.

At first I (following the system's specs) used a SFTP over SSH connection type and indeed it worked fine.

enter image description here

I researched how one can access a remote resource using SFTP over SSH in PHP, and I got the ssh2 set of commands... But my server doesn't have ssh2 commands installed, nor am I familiar with how to further deal with that in terms of listing and downloading remote files, etc (I'm used to plain ftp_connect(), ftp_login() and ftp_nlist() commands)...

So I tried other options in my FTP client app, and found that despite the new system's specs, it connected fine using FTP using explicit SSL (Auth SSL) and FTP using explicit SSL (Auth TLS) connection types also (the only difference is that in those cases I got a popup asking me to accept and store the remote certificate. Of course I got a list of the remote files also...

So, I researched the implementation of FTP connection using explicit SSL in PHP and got the ftp_ssl_connect() command which is a direct replacement to ftp_connect(). So I thought that anything else could stay the same in my code... But to my disappointment I couldn't get a remote file list using ftp_nlist() command (I'm getting a boolean false instead).

So let me give you the list of commands I used, and the outcome presented in the console:

$conn = ftp_ssl_connect( $ftp_address );
$login = ftp_login( $conn, $ftp_username, $ftp_password );
$files = ftp_nlist( $conn, '.' );

var_dump( $conn );
var_dump( $login );
var_dump( $files );

which returned

resource(4250) of type (FTP Buffer)
bool(true)
bool(false)

I also tried using passive mode before ftp_nlist(), like this:

$conn = ftp_ssl_connect( $ftp_address );
$login = ftp_login( $conn, $ftp_username, $ftp_password );
ftp_pasv( $conn, true );
$files = ftp_nlist( $conn, '.' );

var_dump( $conn );
var_dump( $login );
var_dump( $files );

which returned a PHP Warning: ftp_nlist(): php_connect_nonb() failed: Permission denied (13) in

Can someone give me an idea about why ftp_nlist() fails while the connection itself succeeds, and also give me a suggestion about how to deal with this? TIA!

Upvotes: 2

Views: 475

Answers (0)

Related Questions