tags:

views:

374

answers:

2

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');
?>
+1  A: 

FTP/S (FTP over SSL) is an entirely different protocol than SFTP (FTP over SSH), and you can't use a SSL library to connect to an SFTP server (or vice versa).

I'm no PHP programmer, but it does seem some options to connect to an SSH server are natively available for your platform.

mdb
I tried using `ssh2_sftp` but still I was not able to connect to secure FTP Server.
+1  A: 

Like mdb said, you need to use the ssh2 extension in PHP. If you're using Linux, it's pretty simple as sudo pecl install ssh2. If you're on OS X you need to either do a svn checkout, or follow the instructions here: http://thirdpartycode.com/2010/01/installing-the-php-ssh2-extension-in-snow-leopard-10-6/

ThirdPartyCode
So you mean to say that I need to install a new pecl package for ssh2. I am working on company's server which is linux.
yes. Unless you built PHP with the extension, depending on your linux distro someone may already have a rpm, or debian package ready for it.
ThirdPartyCode