I am generating a small script that manipulates a file name, renames the file, and moves it to a directory within it's current directory.
The problem (I think) is that I am running a local PHP Script from my computer and trying to have it do the manipulation on a network drive (R:\ in this case)
I decided, since I'm using Windows 7, that I'll be using the rename() function. Here is the snippet of code..
if (!empty($_REQUEST['uploaded_file']))
rename("R:\\".$fileName, "R:\\Movies\\".$newFileName);
Note: $filename and $newFileName are pulled earlier in the script
The resulting error is:
Warning: rename(R:\movie.title.2011.avi,R:\Movies\Movie Title [2011].avi):
The system cannot find the path specified. (code: 3)
The code use to work for a while, but for whatever reason, all of the sudden, it doesn't want to work anymore.
I'm not sure if using the rename scheme is the best approach for getting this done.. My Synology DS1010+ didn't like me using SFTP to connect and rename too many times.. It eventually started to refuse connections, so I needed to do this differently..
Environment Information:
Operating System:
Windows 7 Ultimate x64
PHP Version: 5.4.4
FileZilla Connection Attempt:
Status: Connecting to 192.168.5.25:21...
Status: Connection established, waiting for welcome message...
Response: 220 Diniz-Stora FTP server ready.
Command: USER admin
Response: 331 Password required for admin.
Command: PASS **********
Response: 230 User admin logged in.
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is current directory.
Command: TYPE I
Response: 200 Type set to I.
Command: PASV
Response: 227 Entering Passive Mode (24,63,165,211,217,0)
Command: LIST
Related
I have a a small PHP script that uses phpseclib to download files from remote server.
The script is like below:
include('Net/SCP.php');
echo var_dump($ssh->exec('whoami')); // debug to test the ssh connection. returns "myuser"
$scp = new Net_SCP($ssh);
try{
$remotePath = '/home/user/test.txt';
$localPath = '/tmp/myfile';
if (!$scp->get($remotePath, $localPath)) {
throw new Exception("Problems to get file");
}
} catch (Exception $e) {
echo "\n\n" . var_dump($e->getMessage()) . "\n\n";die;
}
There are some other questions here in SO that uses very similar snippets.
It works like a charm for many files, but it fails for some binary files ($remotePath = '/home/user/test.p12';, for instance).
Are there any know limitation to download binary files using phpseclib (I didn't find anything in their issues on github)? If not, what I'm doing wrong? Am I forgetting some options or anything?
As a side note scp myuser#serverip:/home/user/test.p12 /tmp/teste.p12 works fine in command line.
Following the comments, I must indicate that my script just fails. The statment $scp->get($remotePath, $localPath returns false for all binary files that I tried. Thats all i have for now.
As far as I know, phpseclib does not have any detailed log on these fails.
My application log (nginx) does not show anything special. Access log on my remote server (centOS. for these tests I have the control over it, but its not the real scenario) I got something like below:
Jul 27 15:22:58 localhost sshd[14101]: Accepted password for myuser from myip port 51740 ssh2
Jul 27 15:22:58 localhost sshd[14101]: pam_unix(sshd:session): session opened for user myuser by (uid=0)
Jul 27 15:22:58 localhost sshd[14103]: Received disconnect from myip port 51740:11:
Jul 27 15:22:58 localhost sshd[14103]: Disconnected from user myuser myip port 51740
PHP version: 7.3 (the script is also used in servers with older versions)
Local server: Debian 10
Remote server: CentOs 8
The problematic file that fires the problem is a certificate p12 file.
I found the problem and it was much more simple than I tought. It was just a permission problem (for any good reason, I put all my test files in a directory without read permition).
I decided to leave this answer here, because I think that this is not clear on phpseclib documentation, but the 'Net/SCP.php' only works with files with read permission, so, before download make sure that the file are readable or execute something like chmod o+r filename.
The snippet in the question works fine with binary files.
I have built Catcoind (a fork of the Bitcoin / project) and I can access the commands in my terminal by doing this from root:
cd catcoin/src
./catcoind -daemon
That will start Catcoind, open the port, and allow me to type commands like './catcoind getdifficulty', but I want to access them from a PHP JSON-RPC client running on another server. The code I currently have there is:
<?php
require_once 'jsonRPCClient.php';
$catcoin = new jsonRPCClient('http://RPCUSER:RPCPASS#IP:PORT');
print_r($catcoin->getinfo());
echo $catcoin->getdifficulty();
My config file for the Catcoind build on Ubuntu is:
server=1
rpcuser=USER
rpcpassword=PASS
rpcssl=0
rpcallowip=*
bind=IP:PORT
externalip=IP
proxy=IP:PORT
port=PORT
rpcconnect=IP
When I run the code, it says that it failed to open the stream / connection refused. The config for Catcoind is at location ~/.catcoin/catcoin.conf. Any ideas? I know this is confusing, but I have really everything done but allowing external IPs to access the API. Thanks! :D
You don't need all these things to be written in conf file just use following
server=1
daemon=1
rpcuser=<user_namer>
rpcpassword=<password>
rpctimeout=30
if connecting from remote host do add following line
rpcallowip=<remote_ip_address>
save and exit from conf file and restart daemon by first stopping it catecoind stop and then catcoind start
Are external IP allowed? If not make sure that the IP is allowed so that it can call the api. The error failed to open the stream / connection refused usually means that the ip and everything is correct but the server rejected the connection.
I use third part framework (exe file) for conneting one php application with taxt service.
Framework is open source, exe file sign xml, give soap cover and send it to central information tax system.
When i open this in batch file (run.bat), all working good:
Raverus.FiskalizacijaDEV.EXE.exe GetInvoice "" "C:\xampp\htdocs\get\racun.xml" "C:\xampp\htdocs\get\OutInvoice.xml" true true "C:\xampp\htdocs\get\certifikat.pfx" "Pwd"
but when i open in PHP using "echo exec('run.bat');" server give me this error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Does anybody have idea how i can resolve this? When i mannualy open batch file (in windows) all working. I use Xampp server.
The PHP user doesn't have the needed configuration or access rights.
If you are unsure which user is running your PHP script, you can use something like this to find out:
<?php
echo '<pre>';
system('set', $retval);
echo ' </pre>';
it should give out information as to which user your PHP is using. Then set up the env for that user so he can run your batch file. This might include importing the certificate for that user.
I'm a student, new to netBean php remote server. I was trying to upload php files to remote server through netbeans (on run). I'm sure everything in run configuration, ftp information is correct, I have rights to upload file to that folder.
And this error occur:
Message prompt:
"Cannot logout from server *name. Reason 250 OK. Current directory: *dir name"
Logs:
Log in output window:
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 17 of 500 allowed.
220-Local time is now 04:13. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
USER a4514022
331 User a4514022 OK. Password required
PASS ******
230-OK. Current restricted directory is /
230-362 files used (3%) - authorized: 10000 files
230 2476 Kbytes used (0%) - authorized: 1536000 Kb
TYPE I
200 TYPE is now 8-bit binary
CWD /public_html
250 OK. Current directory is /public_html
CWD /public_html
250 OK. Current directory is /public_html
Summary
Failed:
file test.php Cannot upload file test.php (unknown reason).
Runtime: 408 ms, transfered: 0 file(s), 0 KB
I don't get what happen. How to fix it?
I use netbean 6.9.1, windows 7 and java ver 7 (build 1.7.0_05) platform 1.7 Those numbers, I don't know which one is the version. I just put all those there. It seems I'm the rare one get this problem...
I Know you asked this and probably your problem has solved
but I write this for the another ones;
first check the Proxy.
Tools>Option>Proxy Settings
and then set on the "no proxy" .
It will probably be solved.
I had to select less secure option e.g. Encryption: Pure FTP option to get it working for GoDaddy setup.
This answer comes even later. I also had the error and ended up here in search.
My mistake was that I had the file I wanted to download in editing with another reader (outside Netbeans). In other words, the downloaded file could not be saved to local filesystem, because the opened file prevented that.
I am trying to send data from an Android app to a PHP file on my server (school server) but I'm running into some problems. I have my own hosting space through SimpleHelix, and I was able to send the data just fine, but when I try to use my school's server, the PHP program returns the following error:
Notice: Undefined index: message in /home/alespurg/test_good.php on line 4
Warning: file_put_contents(androidmessages.html) [function.file-put-contents]: failed to open stream: Permission denied in /home/alespurg/test_good.php on line 9
Warning: file_get_contents(androidmessages.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/alespurg/test_good.php on line 11
All I have changed in my Java file is the URL that I need it to post to. Could there be restrictions on my school's server that prevent the post to go through? I've checked my permissions on the folders and files, they're all 775. Again, I know the program works, I'm just having problems with the server. I did not use the IP address of the domain for either one. I couldn't find it for my school's server.
EDIT:
<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$message=$_POST["message"];
// specify the file where we will save the contents of the variable message
$filename="androidmessages.html";
// write (append) the data to the file
file_put_contents($filename,$message."<br />",FILE_APPEND);
// load the contents of the file to a variable
$androidmessages=file_get_contents($filename);
// display the contents of the variable (which has the contents of the file)
echo $androidmessages;
?>
If the permissions are 775 that means that if the web server process isn't either (1) the user who owns /home/alespurg/ (not likely) or (2) a member of the group that owns /home/alespurg/ (also not likely) then it won't be able write to the directory.
Are you sure the web server process is the owner or a member of the ownership group for /home/alespurg/?
I'll assume your web server is apache, which usually runs as apache:apache or nobody:nobody. Judging from the directory structure, it's likely that /home/alespurg/ is owned by alespurg:alespurg or some derivation.
ADDENDUM
If you need to do things like this an apache process is not really the appropriate place. You may not know it but you can write php scripts and execute them from the shell environment on your server where you're logged in as the appropriate user to write to that directory. Further, you can have CRON run them for you if necessary. The web server process is an unnecessary middleman.