开发者

Does anyone know a SSH/ SFTP/ FTP wrapper around pfsockopen()?

Does anyone know a SSH/ SFTP/ FTP wrapper class around pfsockopen();?? I'm stil开发者_StackOverflowl on my quest to keep persistent connections in PHP.


After a quick read, it looks like opening a socket deals with a different layer then what you are wanting. You want to connect via SSH or SFTP, which is the Application Layer using a method that makes connections via TTP/TLS/UDP, which is the transport layer.

So really what you want (I think) is to create an SSL or TLS connection using the pfsockopen() function, and then use that connection to pass data via the SSH/SFTP protocol.

According to the PHP site:

If you have compiled in OpenSSL support, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.

So my best guess is that you set your hostname to start with ssl:// and then use the SSH or SFTP port as the port (so port 22 or port 989). Something like:

$persistent_socket = pfsockopen("ssl://myhostsite", 22);

or

$persistent_socket = pfsockopen("ssl://myhostsite", 989);


@user260294: Thank you so much for http://phpseclib.sourceforge.net/. Although unrelated to original question, it saved me hours of coding on a similar project.

@Simon: You haven't seen anyone using pfsockopen() specifically with SSH / SFTP due to the fact that it does not work for these specific protocols. The idea is that if a connection already exists you are able to reuse it with pfsockopen without resending any headers, but this is not allowed with daemons listening on port 22. You have no other choice but to reestablish the connection and resend the headers. This applies to anything that deals with SSH1/2/SFTP.

In the case of a daemon that establishes a persistent connection - when it times out you have to reconnect all over... So I don't see much of a point in doing that.


Here's an SSH / SFTP wrapper class around fsockopen():

http://phpseclib.sourceforge.net/

It's not pfsockopen() but maybe replacing the one fsockopen() call with pfsockopen() will do the trick?


wow the package at http://phpseclib.sourceforge.net/ works perfectly for sftp connection and no need to install or add modules or anything. It just works. Thanks sooo much


I Dont know of a class implementation built around that but there is an ssh2 module if that helps you...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜