3

I appreciate any help that can be offered on the subject. At the end of an online enrollment, I am taking customer data (several fields), putting them in a CSV file and trying to submit to another client over SSL protocol but have no idea how this is done. I am also storing the information on a local database and am hoping the process is somewhat similar.

I have already been sent links to view the SSH2 instructions from php.net SSN2

but to be honest this is like reading Chinese to me. I do not understand the instructions and am not looking to install any extensions, modify the PHP.ini file or anything of the sort (especially since we do not own the server the information is being sent through).

Is there a simple, secure way of transmitting this file to the SSL protocol provided to us?

Thanks!

JM4
  • 6,740
  • 18
  • 77
  • 125
  • So, you are interested in using sftp or FTP-ssl? – WhirlWind May 17 '10 at 18:11
  • @WhirlWind - our client set up the following: Created secure FTP account and opened port 990 on the firewall for SSL connections on the FTP server. I also created a new certificate request for the FTP protocol, and choose 1028 bit SSL security Certificate. – JM4 May 17 '10 at 18:18
  • Probably find some instructions for FTPS, instead of the SSH stuff, since that's what it sounds like the "client" wants. – WhirlWind May 17 '10 at 18:22
  • @WhirlWind - you think that's what I need to do - considering that is the topic of my question and what I asked above? Thanks for the insight – JM4 May 26 '10 at 14:31
  • yes, I made that comment because you seem confused between SSH and SSL. They are two different things, and you say this is "Chinese to you." I didn't include it as an answer because it wasn't very complete. Good luck. – WhirlWind May 26 '10 at 14:55

2 Answers2

6

Perhaps you could use ftp_ssl_connect for that matter, which is used to open a secure SSL-FTP connection, and to upload a file is just a straight forward process, just create the connection to the server, and put the file up there. A basic example could be:

//Create your connection
$ftp_conn = ftp_ssl_connect( $host, $you_can_provide_a_port );

//Login
$login_result = ftp_login($ftp_conn, $user, $pass);

if( $login_result )
{
    //Set passive mode
    ftp_pasv( $ftp_conn, true );
    // Transfer file
    $transfer_result = ftp_put( $ftp_conn, $dest_file_path, $source_file_path, FTP_BINARY );

    //Verify if transfer was successfully made
    if( $transfer_result)
    {
        echo "Success";
    }
    else
    {
        echo "An error occured";
    }
}

For reference purposes http://www.php.net/manual/en/function.ftp-ssl-connect.php

falomir
  • 1,159
  • 1
  • 9
  • 16
  • thank you for the advice. I will give it a shot and let you know the results! – JM4 May 17 '10 at 22:57
  • this did not work as needed. I am given the client $host as IP address and it simply times out after 60 seconds. I know the FTPS works because I am able to connect with local FTP client – JM4 May 25 '10 at 20:43
  • 1
    If the above doesn't work. And the connection does work via a desktop FTP program you probably have this problem. http://www.elitehosts.com/blog/php-ftp-passive-ftp-server-behind-nat-nightmare/ – Tim Dec 07 '11 at 05:40
2

The only way I've managed to do ftp over SSL using php was to use php's exec() function to execute a curl command. PHP's curl library would not work because at the time, the skip-pasv-ip option did not exist and it was something that was absolutely required. Something like:

curl --user <username:password> --disable-epsv --ftp-pasv --ftp-skip-pasv-ip --ftp-ssl --sslv2  --cert <path/to/certificate> -T <path/to/uploadfile> <hostname>

You may need to modify the curl options to suit your needs.

Rob Apodaca
  • 834
  • 4
  • 8
  • Thanks for the advice. I am not familiar with Curl but i will give this a shot and let you know how it turns out! – JM4 May 17 '10 at 22:57
  • @JM4 - Also wanted to point out that you might be able to use PHP's curl library. I wasn't able to use it because I could not set the ftp-skip-pasv-ip option - it wasn't available for the version of PHP I was using. If you don't need that option and have curl support available to you, give that a go first. – Rob Apodaca May 18 '10 at 19:11
  • I am not sure how to use curl inline as you have denoted above. I also referenced (http://curl.haxx.se/docs/manual.html) and they list inline just like you did. All of the CURL instructions I have seen are multiple lines with very specific options. I am trying to connect to a host IP, with given username and password, then dump a file in a specific directory. Any ideas? – JM4 May 25 '10 at 20:45