FTP fopen() error 550—not a plain file - php

Well, this is a problem I have never seen before.
I am trying to stream an FTP file using PHP's fopen() and feof() in order to copy it from one server to my own. This works fine when using normal http:// URLs. However, when using the ftp:// protocol, I'm receiving the following error:
fopen(ftp://.../streaming/planted2.mp4) [0function.fopen0]: failed to open stream: FTP server reports 550 /streaming/planted2.mp4: not a plain file.
Bear in mind that I have confirmed the URL is correct.
If I pop it into my browser's search bar, it always loads correctly.
Following this error, any attempt to use feof() or fread() on the wrapper results in an error complaining that the respective function expects a resource, but that instead a boolean is being provided. This would not be the case if fopen() was not failing.
As the files are quite large (several gigabytes at times) streaming is mandatory. Also, due to the configuration of the server, I need a way to loop through each chunk in order to buffer some output. If I don't, the server holds up. It's a weird configuration on Rackspace's behalf. That's why I'm using feof().
So, without further ado, my question is this: What does the 550 error mean, and what is a "plain file"? If it is a problem with the configuration of the server I am attempting to download from, what are my options, given my limitations?
EDIT
I have determined this is a server issue. However, the problem is still unresolved.
I contacted my boss and our server administrator, and the server guy told me to test this out on a different Windows-based server instead of the Linux-based one I was playing with. My script works with the Windows server, so I have confirmed my script is not in error.
Unfortunately, my boss still wants me to figure out the problem, and find out why it's not working on the Linux box. I have absolutely no idea why, and don't know where to look. Any hints would be greatly appreciated!

I've just come across this issue when trying to get a file from a sco unix server.
Server File Location: /home/user/data/myfile.csv
I can put the below into any browser and it gets the file.
ftp://user:password#host/data/myfile.csv
However if I run the below, I get the same error as you
$f = fopen("ftp://user:password#host/data/myfile.csv", "r");
However, if I put the full path into fopen - it works fine.
$f = fopen("ftp://user:password#host/home/user/data/myfile.csv", "r");
I'm not sure if this will fix it for you, but works for me.

Related

PHP file uploading doesn't work over 65KB

I have a VB.NET software that uploads files using an HTTP request to PHP. This worked fine until May but now it fails when uploading files over 65KB. I can not tell when it stops to work exactly. Even though, I don't think it is relevant. So to be clear, uploading a file under 65KB works correctly.
I looked with my hoster and he doesn't see any error neither do I on the server (the part I have access). VB.NET doesn't give me a pertinent error, but using WireShark, I've been able to get either a 500 or a 400 error. But it didn't give me clues on what is failing.
I verified this question which is not solved, though the things said there are OK on the server too.
PHP not uploading file over 55 kb
I have another option to fix it: splitting my files in chunks of 50KB and rejoining them via PHP. Though, I rather understand what is happening because this can happen again even with chunks of 50KB.
Server is Apache/2.4.28 (Unix)
EDIT 1
I have new conditions: I now have my own server running on Windows + Apache 2.4 + PHP 5.6.
Now it goes a little farther. I have an error when using move_uploaded_file function that gives me: Error #3: The uploaded file was only partially uploaded. It is coherent with the file being stopped to be sent near the end. So I now receive an HTTP 200 response but a failure after ward even though I suspect not being there.
I can certify I did not stop my VB.NET software that is uploading the file.
I tested changing KeepAlive to Off/False on both sides. No luck :(
Tried to add header ("Connection: close"); in my main file (that is used for all transactions with this VB.NET software). No luck.
Even though, it is not currently an issue, I changed (PHP configs) the upload_max_filesize to 256M and post_max_size to 300M (because it will be a problem if a can figure out this one).
I got those suggestions from : https://wordpress.stackexchange.com/questions/176465/failed-media-upload-the-uploaded-file-was-only-partially-uploaded
The only one I could not try is replacing an apache/php module which doesn't seem to exist on Windows.
Depending on your server's configuration, when an error 500 is returned an error_log is written. The problem is with the error 400. Which according to wikipedia's list of HTTP codes is actually a BAD REQUEST. Some output from your error_log when the attempt is being made might put us in the right direction.

PHP file_get_contents sudden failure on server

I was using file_get_contents() to fetch information from an external URL. It was working perfectly on the server before. But now, somehow it fails to work on the server. (No changes in the codes.) It keeps giving me the error: failed to open stream: Connection timed out.
I have tested it on localhost and it works perfectly. I have checked allow_url_fopen option, it is still On.
So, what could be the reason(s)?
file_get_contents does not work well at all with getting remote files and should not be used. It does not deal with slow network connections or redirects, and does not return error codes. You should use curl instead to fetch remote files.
There is an example in the manual for curl_exec:
http://us3.php.net/manual/en/function.curl-exec.php

why I have file_get_content warning

I used file_get_content() to read from the uploaded image temp file and store in database.
Everything is work fine except this warning. It show every page of my site. And there is no such page "footer.php". Is it the server problem or I need to change that function.
Warning:
file_get_contents(http://admanager.nethosting.com/getads/www.mogoke.5gbfree.com/):
failed to open stream: Connection timed out in
/usr/share/php/footer.php on line 11
The problem is another invocation of file_get_contents, which downloads advertisements from a remote server, but that download fails due to network problems or a firewall.
This looks very much like your code or server had a security vulnerability and someone uploaded code that includes ad banners on your website (but the money for the clicks of course goes to the crooks instead of you). Removing the malware (i.e. the added advertisement lines, probably heavily obfuscated) should suffice. See this security.stackexchange.com question for more details.

Why does my fopen() randomly stop finding the target path?

Have been trying to solve an issue with out client updater for a couple days now. It compares the file structure on our SVN to client ftps and updates/removes where necessary. I've come to the conclusion that some files don't get updated because of a
if ($stream = fopen($path))
that all of a sudden (after many successful attempts) fails. I'm not including too much code because I doubt it would help. It all quite abstract and full of defines.
What happens is I upload a couple scripts to the server, run them and then delete them again. These scripts get called with fopen().
But for some reason after a bunch of fopen() calls to the uploaded script (before the delete, I have checked this and made sure the scripts successfully get uploaded aswell)
it all of a sudden throws this error
fopen(http://www.mysite.com/back_it_up.php) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Anyone have any idea what might be interfering with my fopen?
Ive tried clearstatcache() and checked the rights of all the files (0755) and done quite a bit of research on this problem already.

imagecreatefromjpeg() error - Why is my image manipulation script failing?

I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.

Categories