I'm trying to create a php script that will put a file on a remote server.
The following line will work from the CLI:
curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/
However, if I take this into PHP and try to run it through 'system' like:
<? system('curl -u username:pass -T myfile.jpg sftp://my.domain.com/dir/'); ?>
I get an error:
curl: (7) Failed to connect to xxx.xxx.xx.xx: Permission denied
Also, to complicate things, this is going from a RHEL to a Windows Server. Anyone have a suggestion or a fix?
Below is the result from the PHP cURL library.
* About to connect() to my.domain.com port 22 (#0)
* Trying xxx.xxx.xx.xx... * connected
* Connected to my.domain.com (xxx.xxx.xx.xx) port 22 (#0)
* SSH authentication methods available: publickey,password
* Initialized password authentication
* Authentication complete
* Upload failed: Permission denied (3/-31)
* Connection #0 to host my.domain.com left intact
* Closing connection #0
PHP has it's own cURL library that you should probably use. php cURL
Your problem is that system() doesn't allow curl to ask you for a password.
Consider other authentication methods.
Related
I have an FTP account I'm trying to list files from but I can't get it to work
FileZilla is able to list them, but only when strictly setting it to active mode rather than passive
Example output from FileZilla
Status: Retrieving directory listing of "/"...
Command: PORT 192,168,68,115,213,202
Response: 200 PORT command successful
Command: MLSD
Response: 150 Opening connection
Response: 226 Transfer complete
Status: Directory listing of "/" successful
In my PHP code I've tried the following
$connection = ftp_connect($host, 21);
ftp_login($connection, $username, $password);
var_dump(ftp_size($connection, 'tarbert.jpg'));
var_dump(ftp_mlsd($connection, '.'));
var_dump(ftp_rawlist($connection, '.'));
var_dump(ftp_nlist($connection, '.'));
Which outputs
int(227978)
bool(false)
bool(false)
bool(false)
As you can see by the call to ftp_size, there are files there and it can see them, but the calls to list the files all return false
I've tried the usual answer of setting to passive mode but that just makes it timeout
Does anyone have any suggestions on what else I could try?
Mini update
Strangely, if I move the ftp_size call to be after the others then that also returns false so it seems like the initial call to list files breaks something
I've tried moving each of the 3 list functions to be the first call but this makes no difference to the outcome
Update with FileZilla full log
Status: Connecting to xx.xx.xx.xx...
Status: Connection established, waiting for welcome message...
Response: 220-Welcome To Rumpus!
Response: 220 Service ready for new user
Command: AUTH TLS
Response: 530 USER and PASS required first
Command: AUTH SSL
Response: 530 USER and PASS required first
Status: Insecure server, it does not support FTP over TLS.
Command: USER my_user
Response: 331 Password required
Command: PASS ******
Response: 230 User logged in
Command: SYST
Response: 215 MACOS Server
Command: FEAT
Response: 211-Extensions supported:
Response: SIZE
Response: REST STREAM
Response: APPE
Response: MDTM
Response: MACB
Response: PBSZ
Response: PROT
Response: EPSV
Response: MLSD
Response: UTF8
Response: 211 End
Command: OPTS UTF8 ON
Response: 220 UTF8 OPTS ON
Status: Logged in
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is current directory.
Command: TYPE I
Response: 200 Type set to I (Image)
Command: PORT 192,168,68,115,204,128
Response: 200 PORT command successful
Command: MLSD
Response: 150 Opening connection
Response: 226 Transfer complete
Status: Directory listing of "/" successful
Update with curl log
curl -v --list-only ftp://XX.XX.XX.XX --user "username:password"
* Trying XX.XX.XX.XX:21...
* TCP_NODELAY set
* Connected to XX.XX.XX.XX (XX.XX.XX.XX) port 21 (#0)
< 220-Welcome To Rumpus!
< 220 Service ready for new user
> USER username
< 331 Password required
> PASS password
< 230 User logged in
> PWD
< 257 "/" is current directory.
* Entry path is '/'
* Request has same path as previous transfer
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||3004|)
* Trying XX.XX.XX.XX:3004...
* TCP_NODELAY set
* Connecting to XX.XX.XX.XX (XX.XX.XX.XX) port 3004
* Connected to XX.XX.XX.XX (XX.XX.XX.XX) port 21 (#0)
> TYPE A
< 200 Type set to A (ASCII)
> NLST
< 150 Opening connection
* Maxdownload = -1
# FILE LIST HERE
* Remembering we are in dir ""
< 226 Transfer complete
* Connection #0 to host XX.XX.XX.XX left intact
Just in case anyone else stumbles on this, it appears the FTP is behind a NAT
See this link for details
http://www.elitehosts.com/blog/php-ftp-passive-ftp-server-behind-nat-nightmare/
I couldn't find a fix as this particular FTP doesn't allow passive connections but if yours does then that link will help
I am trying to get the version of tls which is currently used when invoking the url.
I'm trying to get the tls version from php curl like the command curl in Ubuntu.
for example:
curl -v https://qpyl.uas-gw.info
* Rebuilt URL to: https://qpyl.uas-gw.info/
* Trying 54.199.158.6...
* Connected to qpyl.uas-gw.info (54.199.158.6) port 443 (#0)
* found 1 certificates in ca.crt
* found 692 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384
like this to show the tls version result.
But I cannot get the version in php curl like the above curl does
SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384
php openssl version: openssl/1.0.2g
php version: 5.5.38.
I have a .ldif file and want to import it using php script to my ldap.
So, i'm using that code:
$comm = "ldapadd -h 'localhost' -p 389 -D 'cn=admin,dc=example,dc=com' -w 'password' -f /var/www/html/test/ldap.ldif";
system($comm,$return);
echo $return;
I'm always getting error code 13 which is:
LDAP_CONFIDENTIALITY_REQUIRED: Indicates that the session is not protected by a protocol such as Transport Layer Security (TLS), which provides session confidentiality.
Looking at ldapadd sintax found these options
-W: Wallet location for one- or two-way SSL authentication
-P Wallet password
-U SSL authentication mode: 1 for no authentication; 2 for one-way authentication; 3 for two-way authentication
But I don't know how or when I have to use them.
My .ldif file contain a lot of new entrys and through php code I couldn't use the:
$info["dn"] = $test;
Always getting errors about that $info["dn"] syntax, so then I gave up and start trying with terminal command.
Would really appreciate some help about it and sorry about my english.
Thank you.
A friend of mine found the answer.
About the code 13 error was missing an option at the end of the command which allows the TLS connection, so, the correct command line is:
ldapadd -h 'localhost' -p 389 -D 'cn=admin,dc=example,dc=com' -w 'password' -f /var/www/html/test/ldap.ldif -Z
So, the option -Z or -ZZ at the end enables the TLS and the error is gone, so it's working the input on ldap with my .ldif file
Thank you all.
I am facing a weird problem here
we have a server A where the app files are stored
and B server with database
Tried to connect via command prompt from server A to B using the command
mysql -h xx.xx.xx.xx -u root -p password - and it worked
NOw i tried to create a php script in server A to connect to server B
the command is
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password');
Connection failed: SQLSTATE[HY000] [2003] Can't connect to MySQL
server on 'xx.xx.xx.xx' (13) Fatal error: Uncaught exception
'Exception' with message 'SQLSTATE[HY000] [2003] Can't connect to
MySQL server on 'xx.xx.xx.xx' (13)'
Unable to find a solution on this.
Can any help on this?
thank you
I got it working by running a command in the database server :)
setsebool httpd_can_network_connect_db=1
thanks for the replies yycdev
Try specifying the port in your connection string and ensure the database server is set to allow remote connections and the port is open on your firewall (both of these I suspect are already done as you are able to connect via the terminal but it never hurts to verify and check things).
Change your PDO connection and add the port=3306 or if you're using MAMP use port 8889
$this->db=new PDO('mysql:host=xx.xx.xx.xx;port=3306;dbname=databasename','root','password');
Another thing to check is if – SELinux is blocking network connections. Login as root and run
setsebool -P httpd_can_network_connect=1
I don't know much about that, but try to place the port in back of the script:
$this->db=new PDO('mysql:host=xx.xx.xx.xx;dbname=databasename','root','password',3306);
I've checked quite a few StackOverflow posts, and still can't find a solution. I'm working with the Dropbox PHP API, but I believe that is irrelevant. What seems to be the issue is that cURL refuses to use the CAPATH or specific certificate provided by Dropbox for connecting to the API, and just gives up. After a series of debugging tests, this is what I got for output from CURLOPT_VERBOSE:
* Adding handle: conn: 0x252c110
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 2 (0x252c110) send_pipe: 1, recv_pipe: 0
* About to connect() to api.dropbox.com port 443 (#2)
* Trying 108.160.167.19...
* Connected to api.dropbox.com (108.160.167.19) port 443 (#2)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* Unable to initialize NSS database
* Initializing NSS with certpath: none
* Unable to initialize NSS
* Closing connection 2
The dropbox API code sets CURLOPT_CAINFO and CURLOPT_CAPATH. I have checked that PHP can access the directory, and that file. I don't understand why cURL says Initializing NSS with certpath: none when I explicitly provided one... Any help would be appreciated.
I had this problem on Amazon ec2 instance (Amazon linux), restarting apache fixed it.
restarting using apachectl was not helpful
so do this using
/etc/init.d/httpd restart