FTP Implicit SSL class - never connects - how to debug? - php

I am trying to connect to an FTP service which requires the user to connect via Implicit SSL. The details are working in CuteFTP so my credentials are 100%.
I am trying to use this class and the connection method below but it just times outs.
Class: https://gist.github.com/maxrice/4544344
<?php
include "../objects/shared/ftp-implicit-ssl-tls.php";
$FTP_Implicit_SSL = new FTP_Implicit_SSL("myuser", "mypass", "rapidata.sharefileftp.com", 990, "Organisations/Avid/RDS_Data", true);
$FTP_Implicit_SSL->upload("text.txt", "text.txt");
?>
There is a simple text.txt file in the same directory as the script.
Fatal error: Uncaught exception 'Exception' with message 'Could not upload file. cURL Error: [7] - Failed to connect to rapidata.sharefileftp.com port 990: Connection timed out
My web host reports the script should be able to connect and this is what they see:
Last login: Wed Apr 29 16:14:57 2015 from 79.174.170.1
root#server-1:~# telnet rapidata.sharefileftp.com 990
Trying 54.194.108.219...
Connected to rapidata.sharefileftp.com.
Escape character is '^]'.
Then eventually
Connection closed by foreign host.
Pleaase - any ideas what is going on here or how to find out?
what about these settings in the class?
$options = array(
CURLOPT_USERPWD => $username . ':' . $password,
CURLOPT_SSL_VERIFYPEER => false, // don't verify SSL
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FTP_SSL => CURLFTPSSL_ALL, // require SSL For both control and data connections
CURLOPT_FTPSSLAUTH => CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
CURLOPT_UPLOAD => true,
CURLOPT_PORT => $port,
CURLOPT_TIMEOUT => 300,
);

Related

Cert validation failed while connecting from PDO PHP to Postgres using SSL

I'm trying to connect from PHP PDO to Amazon's PostgreSQL DB instance using SSL. I'm using the following DSN:
$db = new PDO('pgsql:host=[host];port=[port];dbname=[db];options=\'--client_encoding=utf8\';sslmode=require;sslcert=/path/domain.crt;sslkey=/path/private.key;sslrootcert=/path/intermediate.ca-bundle;', '[user]', '[pass]');
I'm using the same sslcert, sslkey and sslrootcert that are used by Apache on the same client server - they are in PEM format. I can connect using SSL to MySQL with them using following PDO options.
$options = [
PDO::MYSQL_ATTR_SSL_KEY => '/path/private.key',
PDO::MYSQL_ATTR_SSL_CERT => '/path/domain.crt',
PDO::MYSQL_ATTR_SSL_CA => '/path/intermediate.ca-bundle',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
];
But for PG, I'm getting:
SQLSTATE[08006] [7] SSL error: certificate verify failed
Without SSL, I can connect with no problem.
Any help would be appreciated!

unable to Curl or SoapClient Any remote_server:8080 port on Directadmin Centos

I am Trying To Connect a Soap Api by php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_1, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 5, 'stream_context' => stream_context_create($opts) );
$url = "http://x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";
$client =new SoapClient($url,$params);
$result = $client->sendMessageOneToMany(array(
"username" => 'xxxxx',
"password" => 'xxxxx',
"originator" => "50004132311446",
"destination" => $numbers,
"content" => $massage,
));
but it allways got an
SOAP-ERROR: Parsing WSDL: Couldn't load from 'x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";' : failed to load external entity "x.x.x.x:8080/ws-relay/MessageRelayService?wsdl";")
error !
I also Tried to Curl This WSDL but I got
[root#myhost ~]# curl http://x.x.x.x:8080/ws-relay/MessageRelayService?wsdl
curl: (7) Failed to connect to x.x.x.x port 8080: Connection timed out
Error !
so i also tried to curl portquiz.net:8080/ for test and i got timeout again !
is there some rule in firewall that block me to send request to 8080 ports !
how can i unblock it in centos directadmin vps ?
often this happens because that your ip address has been blocked , or there are an issues with the server it self .
for more info about that , libcurl error codes
CURLE_COULDNT_CONNECT (7)
Failed to connect() to host or proxy.
for your command :
curl http://xx.xx.xx.xx:xxxxws-relay/MessageRelayService?wsdl
when executing it in my own pc i got the response normally .
so you will need to use proxy in your SoapClient class
For making an HTTP connection through a proxy server, the options
proxy_host, proxy_port, proxy_login and proxy_password are also
available.
so you will need to add some params to your $params array ass follows :
$params['proxy_host'] = "proxy_ip";
$params['proxy_port'] = "proxy_port";
it's also possible (personally i recommend this) to use procedures libcurl functions or packages built on it.
if you want to use the cli way , so your command may be some thing like this :
curl http://xx.xx.xx.xx:xxxx/ws-relay/MessageRelayService?wsdl -x "ip_address:ip_port"
for socks5 ips
curl http://xx.xx.xx.xx:xxxx/ws-relay/MessageRelayService?wsdl -x "ip_address:ip_port" --socks5

Connecting to Gmail via Horde_Imap_Client

I have tried to connect to mit private as well to my google apps for work inbox via IMAP using the Horde_Imap_Client. I have used the following config:
$config = array(
'username' => $username,
'password' => $password,
'hostspec' => 'imap.gmail.com',
'port' => '993',
'secure' => true,
"debug" => "imap.log",
"debug_literal" => true
);
I also tried ssl, sslv2, sslv3 and tls for the secure value. The Exception i got was Error when communicating with the mail server. and the imap.log only showed me this
------------------------------
>> Thu, 28 Jan 2016 18:29:14 +0100
>> Connection to: imap://imap.gmail.com:993/
>> Server connection took 0.0156 seconds.
>> Slow Command: 10.018 seconds
>> ERROR: read/timeout error.
------------------------------
I also tried allowing "insecure apps" in my google account but the result was the same. Any clues? The connection works fine with our in-house IMAP server and the office365 IMAP server
Change
'secure' => true,
to
'secure' => 'tlsv1',
This will force TLSv1 connections.
I ran into this same problem myself. I posted to the Horde mailing list but was able to resolve the issue a day later on my own with the above change.

How to use php cURL on local vagrant?

I have the following piece of code which works on my remote server
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => "http://{$_SERVER['HTTP_HOST']}/social/api/auth/login_or_register",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($credentials)
));
$exec = curl_exec($myCurl);
I decided to port the project to local for further development so I have set up a vagrant virtual machine with everything needs, everything seems to work normally except the piece of code above which gives me the following error:
Curl failed with error #7: Failed to connect to project.dev port 8000: Connection refused
Any hints on how I can work around this problem so that I can develop normally on local ?
add in /etc/hosts
127.0.0.1 project.dev

Unable to Connect to ssl

I have configured the openssl with wamp (Apache server). But while I using gdata api I'm getting following error.
( ! ) Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message ' in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
( ! ) Zend_Http_Client_Adapter_Exception: Unable to Connect to ssl://accounts.google.com:443. Error #10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Zend_1_11_11\library\Zend\Http\Client\Adapter\Socket.php on line 234
Somebody help me on this...
Solution only for Windows users:
Check the SSL module is enabled in php.ini:
extension=php_openssl.dll
Answer from Mikhail does not work for me as I run it in Alpine Linux and .dll is only windows extension. Do not use it outside of Windows, it only adds warnings.
Solved my problem:
I had a self-signed certificate that was unable to establish connection.
To check that it is problem you can make a request:
wget way:
// not working:
wget https://accounts.google.com:443
// working:
wget https://accounts.google.com:443 --no-check-certificate
or curl way:
// not working:
curl https://accounts.google.com:443
// working:
curl https://accounts.google.com:443 -k
To temporary solve it in my dev docker container, I have added use of curl adapter and no check for certificate to the code:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => [CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false]
);
$client = new Zend_Http_Client('https://example.com', $config);
You are behind proxy, so you can not connect directly.Try to use Zend/Http/Client/Adapter/Proxy.php instead of Zend\Http\Client\Adapter\Socket.php
If you on Ubuntu try add in your php.ini
openssl.capath=/etc/ssl/certs
For more info read this issue

Categories