Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using phpseclib to close a Net_SFTP connection

I have a program written in PHP that distributes files to various FTP sites. Recently, I added SFTP support to it using phpseclib. It's very easy to use to log in and upload the files.

However, there doesn't seem to be an explicit function to close a connection. This is important to me because I'm dealing with connecting /disconnecting to a number of sites during the processing.

How can I close a Net_SFTP connection?

like image 221
David Spencer Avatar asked Apr 23 '15 16:04

David Spencer


People also ask

How to close SFTP connection in php?

For PHP 5. x similar functionality, try setting the ssh2_connect session variable to null, or unsetting it completely - this should allow PHP's garbage collection close the connection. $sftp = ssh2_sftp($connection); $connection = null; unset($connection);

What is SFTP PHP?

Learn how to connect to SFTP, list files, upload and download using the PHP programming language. Guides Engineering. SFTP is a standard and secure protocol through which parties can safely transfer and share data and files. In any case, engaging with an SFTP server programatically can be challenging.

How install Phpseclib on Windows?

Unzip the downloaded files. You will find a phpseclib folder that would need to be placed on your project folder. For instance, a script to login, to a SFTP server, with an user and password would require the Net/SSH2. php and Net/SFTP.


1 Answers

Does undefining your connection work (as mentioned in this Perl 5 example)?

unset($sftp);  

where $sftp is the variable holding your connection.

like image 133
Christopher Bottoms Avatar answered Sep 18 '22 22:09

Christopher Bottoms