PHP ftp_connect() fails to connect to my ftp server


#1

Hello,

I am trying to connect to my ftp server using PHP ftp functions but it shows error message. Please help me to solve this issue.

[php]

<?php $server_host = "ftp.testing.designerashok.com"; $server_connect = ftp_connect($server_host, 22) or die("Could not connect to $server_host"); ; if($server_connect){ $server_login = ftp_login($server_connect, "ftpusername", "ftppassword"); } if(!$server_login){ echo "You don't have access FTP server"; } else{ echo "FTP Server connection is established."; } ?>

[/php]


#2

In the dreamhost panel what kind of user do you have? FTP user, SFTP user, or Shell user? If its an FTP user that may explain why you can’t get logged in. Your code says to use port 22 which is SFTP.


#3

It would also help to see the exact error message and error logs, even.


#4

Yes, I am using SFTP. For this reason, i have specified port is 22. If i removed it, it shows another error message. I think, everything is correct in my code but it is not executing and it is failed at ftp_connect() function.

You can check it at http://testing.designerashok.com/file-upload.php

Does DreamHost require any other setting or programming factors to use such functions?
[hr]

I am testing this code at http://testing.designerashok.com/file-upload.php

It shows error [quote]Could not connect to ftp.testing.designerashok.com[/quote]

Should i change the host name for SFTP? I could not understand why my basic instruction fails to connect to FTP by PHP function. Please guide me to solve this issue.


#5

FTP and SFTP are two totally different protocols, that’s why your function is failing to connect: it expects plain FTP and finds an encrypted connection instead.

I’m no php expert but probably this is what you need to use: http://php.net/manual/en/function.ssh2-sftp.php