dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Failed to connect using ftp_connect

  1. #1
    Join Date
    Sep 2006
    Posts
    4

    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";
    exit;
    }
    else
    echo "Connected!";

    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.
    Thank you.

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    In order to use FTP functions with your PHP configuration, you should add the --enable-ftp option when installing PHP 4 or greater

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    also, you need to ensure that an actual FTP server is running on the system you are connecting to.

  4. #4
    Join Date
    Sep 2006
    Posts
    4
    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.
    Thank you.

  5. #5
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    do you need to go through SSL for this connection maybe?

  6. #6
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Have you got display errors enabled and set to E_ALL?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles