SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem with PHP's FTP functions when attempting SSL connection

    I've made every possible connection to verify that the FTP server is working correctly, and can even use file_put_contents() to upload a file, but PHP's FTP functions are not working for me when attempting an SSL connection. The server is configured to not allow connections that are not SSL, so there is no fallback. That's OK, everything still works, but I really want to use ftp_ssl_connect() and ftp_login() to work!

    See this example:

    PHP Code:
    <?php

    $username    
    'someuser';
    $password    'SeCrEtPassWd';
    $hostname    '192.168.1.10';
    $filename      'whatever.txt';
    $string_data  'This is the text content of the file. Pretty fancy eh?';


    // USE file_put_contents W/ stream_context_create - WORKS !!!!
    $url 'ftps://' $username ':' $password '@' $hostname '/';
    $opts = array('ftp' => array('overwrite' => true));
    $context stream_context_create$opts );
    file_put_contents$url $filename$string_data0$context );
    // END of code that works -----------------------------------


    // USE PHP's FTP functions - DOES NOT WORK !!!
    $conn_id = @ftp_ssl_connect$hostname );
    $login_result ftp_login$conn_id$username$password );
    ftp_put$conn_id$filename$filenameFTP_ASCII );
    ftp_close$conn_id );
    // END of code that does not work ---------------------------


    /*
    ERRORS PERTAINING TO THE PROBLEM ----------------------------

    Warning: ftp_login() [function.ftp-login]: SSL/TLS handshake failed in C:\xampp\htdocs\script-library\ftps.php on line 20
    Warning: ftp_login() [function.ftp-login]: Proceed with negotiation. in C:\xampp\htdocs\script-library\ftps.php on line 20
    */

    Is this a bug in PHP? I just don't understand why everything else works, but not the PHP FTP functions. My problem is that I really need to be able to list the files on the remote server, because I don't want to overwrite them. I would want to rename the file to something that doesn't exist.

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Austin
    Posts
    401
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is openssl compiled into this php build?

    Secondly, are you certain you're supposed to be connecting with ftps and not sftp?
    Merchant Equipment Store - Merchant Services, POS, Equipment, and supplies.
    Merchant Account Blog | Ecommerce Blog

  3. #3
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, OpenSSL is showing as enabled when I look at phpinfo(). I can access the website using http://...

    So I don't know if that means openssl is compiled in this php build or not. The dev machine is running XAMPP on Windows 7 64 bit, if that means anything.

    And yes, I must connect with ftps and not sftp.

    I actually came up with a solution using is_file and the ftps:// wrapper. I won't actually need to get the FTP functions working anymore, but it would be better if I did, because it means doing extra work on my end.


Tags for this Thread

Bookmarks

Posting Permissions

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