Failed to connect using ftp_connect
Hi, I'm new to FTP using PHP. I need to ftp a remote server to retrieve and save a file to my local C: drive. The very first step I did is:
$ftp_server = "202.xxx.xxx.xxx"; //xxx will be replaced with remote server IP address
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = "testuser";
$ftp_user_pass = "testuser";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result))
echo "FTP connection failed";
I always failed to connect to the server. Hence, I tried using my own computer IP address and username & password, but the connection failed too. What's wrong with my code?
Please enlighten me.
In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP 4 or greater
also, you need to ensure that an actual FTP server is running on the system you are connecting to.
Hi Bokeh and Chazzy, thank you for your reply. FYI, my Apache server has --enable-ftp option and the actual FTP server is running. I tried to connect to the remote server using a FTP software and it works well. In other words, there's problem with my php script. I really have no idea what goes wrong. Please help.
do you need to go through SSL for this connection maybe?
Have you got display errors enabled and set to E_ALL?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)