Page 1 of 1

SSH2_connect

Posted: Mon Feb 23, 2009 6:15 pm
by mmajidi
I am using SSH2_connect for ssh connection to an SFTP server. I want to close the connection after performing some SFTP function. What is the PHP function to disconnect from a SSH2_connect?

Re: SSH2_connect

Posted: Mon Feb 23, 2009 6:22 pm
by ~BlitZ
Hmm, Im not sure about that, Once you are connected, Try to use

Code: Select all

ssh2_fingerprint()
That should secure it a bit, Erm, After you

Code: Select all

 
echo "You have been logged out";
}
die;
My code is probably completely wrong, Still picking php up so. My try :D

Re: SSH2_connect

Posted: Tue Feb 24, 2009 1:46 pm
by mmajidi
What does ssh2_fingerprint do? It has nothing to do with disconnect? I am looking for a function to disconnect me from the server once I get connection to it using ssh2_connect.

Re: SSH2_connect

Posted: Tue Feb 24, 2009 2:04 pm
by ~BlitZ
Yeah i think you can just use the Die; Functions, The fingerprint is to secure logging in. You can see how to use it here,
http://www.php-manual.at/function.ssh2-fingerprint.html

Re: SSH2_connect

Posted: Tue Feb 24, 2009 10:16 pm
by mmajidi
I am assumuing that there is no ssh2_disconnect.

ssh2_connect();
write or read some functions // this will write and read files on the sftp server
ssh2_disconnect();

Re: SSH2_connect

Posted: Tue Feb 24, 2009 11:03 pm
by ~BlitZ
I had a look and i couldn't see one.

Shouldn't it exit when you close the page?

Re: SSH2_connect

Posted: Wed Feb 25, 2009 2:09 am
by ubl_
~BlitZ wrote:Hmm, Im not sure about that, Once you are connected, Try to use

Code: Select all

ssh2_fingerprint()
That should secure it a bit, Erm, After you

Code: Select all

 
echo "You have been logged out";
}
die;
My code is probably completely wrong, Still picking php up so. My try :D

I my application I use php as a script, where I need to connect through SSH2 to a lot of linux box'es.
I therefore need to be able to disconnect.

I too was also wandering about how to disconnect from a ssh2 connection, as I can not make it disconnect before the script ends. :banghead:
(Its nice that I am not only one who does not understand it)

The "ssh2_fingerprint()" has nothing to do with disconnecting: (sorry...)
http://www.php.net/manual/en/function.s ... rprint.php
It just makes you able to verify the host.

I tried using "die;" at the end of my function, but it does not close the connection fully! :-)
I get the same result as when using "unset($connection_ssh);" on my connection
($connection_ssh = ssh2_connect($connect_str['ip'], $connect_str['port']))

Just for test purpose:
If I pause the script at the end I can see that the SSH2 connections does not close fully until PHP ends.

To test this on Windows I use the command "netstat -b" in the command prompt, where I can see the following:

Trimmed output from the command prompt:
TCP dkmvpn7aaa:2748 192.168.117.11:ssh CLOSE_WAIT 10644
[php.exe]

TCP dkmvpn7aaa:2754 192.168.117.11:10022 CLOSE_WAIT 10644
[php.exe]

Re: SSH2_connect

Posted: Wed Feb 25, 2009 8:18 am
by ~BlitZ
Fingerprint function is for when you are logging in not when you are logging out, I think it just secures who is accessing it.

And with the Die; function not fully closing it, I'm stuck. I don't think there is another way :/
I'll just keep searchin google for a way :D.