PHP ftp_connect() fails to connect to my ftp server


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 $server_host = ""; $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."; } ?>


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.

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

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

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

I am testing this code at

It shows error [quote]Could not connect to[/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.

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: