Connect to server via sftp php

how do we connect to a remote server via sftp to check if login details in php are valid ...

I am using apache server ... my use is to check if the user data entered by the user is entered correctly.

+4
source share
4 answers

You may have an easier time using phpseclib, a pure PHP SFTP client . Here is an example:

<?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()); ?> 

The problem with libssh2, like all recommendations, is that it is not very widespread, this API is not quite the most reliable, it is unreliable, poorly supported, etc.

+3
source

Is Apache Server Installed? for example: xampp?

If you do this, you use the FTP function:

 <?php $connection = ssh2_connect('ftp.server.com', 22); //port 22 for Shell connections ssh2_auth_password($connection, 'username', 'password'); $shell_ftp = ssh2_sftp($connection); $connectionStream = fopen('ssh2.sftp://'.$shell_ftp.'/path/to/fileorfolder', 'r'); if(!connectionStream) { echo "Could not connect to the server, please try agian"; } else { echo "Successfully logged in."; } ?> 

To establish a basic connection to the Shell server, you must specify the absolute path to the file or folders.

+2
source

will it help

 <?php $connection = ssh2_connect('ftp.server.com', 22); if (ssh2_auth_password($connection, 'username', 'password')) echo "Authentication success"; else echo "Authentication failure"; ?> 
+2
source

I created a small library of several sentences. I use

idct sftp client on github

0
source

All Articles