使用PHP保护FTP连接 [英] Secure FTP Connection using PHP
问题描述
我有一个安全的FTP服务器,登录详细信息和PHP,我试图使用 ftp_ssl_connect / ftp_connect
和连接到该安全FTP服务器。 ftp_login
函数并正确地将所有参数传递给该函数,但我很惊讶地发现它没有连接。
如果我尝试连接从命令行使用SSH安全的FTP服务器比我能够做到这一点,但是当我试图通过PHP代码连接,它不会连接,所以我不知道为什么会发生这种情况?
使用PHP连接到安全FTP服务器的其他方法是什么?
编辑:我尝试使用 ssh2_sftp
但仍然无法连接到安全的FTP服务器。
编辑2 :有没有其他方法可以用PHP来执行SFTP,请指教。
更新:添加了使用ssh2_sftp连接到安全FTP服务器的代码,但它没有奏效,程序因消息无法连接到服务器
<?php
$ connection = ssh2_connect ('www.server.com',22);
ssh2_auth_password($连接,'用户名','密码');
$ sftp = ssh2_sftp($ connection)或死(无法连接到服务器);
$ stream = fopen(ssh2.sftp:// $ sftp / path / to / file,'r');
?>
a href =http://phpseclib.sourceforge.net/ =nofollow> phpseclib,一个纯粹的PHP SFTP实现。不要紧,PECL扩展很难安装,但它也不可靠,不便携。
I have an secure FTP Server with the login details and from PHP, am trying to connect to that secure FTP Server using ftp_ssl_connect/ftp_connect
and ftp_login
function and passing all the parameters properly to the function but I am amazed to see that it does not connect.
If I try to connect to that secure FTP Server from command line using ssh than I am able to do so but when I am trying to connect through php code, it does not connect and so I am not sure why this is happening ?
Also what are the other ways to connect to Secure FTP Server using PHP ?
EDIT : I tried using ssh2_sftp
but still I was not able to connect to secure FTP Server.
EDIT 2 : Are there any other ways to do SFTP with PHP, please advise.
Update : Added code which used ssh2_sftp to connect to secure FTP Server but it didn't worked and program died out with message Cannot connect to Server
<?php
$connection = ssh2_connect('www.server.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection) or die ("Cannot connect to server");
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
?>
I've had quite a bit of success with phpseclib, a pure PHP SFTP implementation. Never mind the fact that the PECL extension is hard to install but it's also unreliable and not very portable.
这篇关于使用PHP保护FTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!