How to set file permission for linux host under windows? - php

For example, i want a file has permission of 644 automatically when i uploaded it to my linux host, before upload, it is under windows. How could i do this?
Btw, i use Filezilla for upload
Updated: Before post this question, actually, i ever thought it is impossible too. But, as i has many wordpress sites, i remembered that i never need to set permission for wordpress files. So i did an experiment,
dowload a new wordpress package, zip format (under windows)
uploaded it to my linux host,
unarchive
check permissions of these files
I saw all files had their permission naturely right, some 644, some 755, exactly as described in wordpress document

I think this is not possible in most cases.
Could you give more information on how you upload? FTP, SFTP, SMB? :-)
For example for FTP you could configure the FTP server in order to give all new files the 644 umask (see this example for ProFTPd).
For SFTP, the client might be able to change the permissions after the upload, because it has SSH access, after all.

You can't. The permission is not written in the file itself, but rather in the filesystem. So it has to be done once the file has being uploaded.

Assuming that you are using FTP to upload the files, better FTP clients (FileZilla) will allow you to set the permissions IF THE SERVER is setup to allow the FTP client to set it.
As far as "default settings", 644 is typically the default already for files. This again is set by the server. I would assume that there is an FTP client out there that will auto set it for every file, but I don't know for sure. If you go monkeying with permissions, remember that directories are 755, not 644, and it is possible that the server could let you remove your own access to the file.

First, what username owns the files? What username do you connect as when you upload?
What is that user's default umask setting?

So you could use the Windows FTP command "quote" which lets you send arbitrary commands to the FTP server.
Assuming your Linux FTP server supports SITE UMASK...
e.g. ftp> quote SITE UMASK 111
This would be equivalent to doing: chmod 666 * on the Linux command line but via FTP on Windows.

Related

Deleting 'Locked' Folders on the server

I have an opencart folder on my server, and I want to delete it, however I can't because my FTP client simply say's:
550 shop_Opencart: Operation not permitted
I understand that some files have different permissions etc but why, as the server admin, can I not delete these files, or change the file permissions? Is there anything else that stops these files from being deleted or modified, other than file permissions?
Even using the control panel (in this case PLESK) I cannot delete them, I get a Permission denied error.
What can I do?
Try chmod the folder using your ftp client and then delete it.
Connect via SSH using Putty as the root user and make the changes via that.

Apache file ownership / group

I currently manage 8 different sites for my organisation and built a central management website to help manage the content on them all.
I currently have a file uploader on the administration website that allows me to upload ZIP files to the server. This script then unzips the package, and moves the files to different parts of the server.
The problem is, when I upload files through the browser, it assigns ownership to apache (for both user and group). This causes me a problem when I try to overwrite the files using FTP.
I have tried to change the owner of the uploaded files as soon as they've been uploaded / moved, both with PHPs native 'chown' function and also using the exec function to run the linux command chown but both fail (PHPs native chown displays an 'operation not permitted' error)
So my questions:
1) Am I going about this the wrong way? (My knowledge of file ownership is limited)
2) Is there a reason why I shouldn't change file ownership?
3) Are there any work arounds?
If you would like any more information, please feel free to ask.
Many thanks
Phil
Current file details of file uploaded via browser:
[file].php permissions: adfr (0644) Owner: Apache Group: Apache
File details of file uploaded via FTP:
[file].php permissions: adfr (0644) Owner: [ftp login name] Group: psacln
I do something very similar of what you do but I dont use ftp, I use scp, part ssh. With this you can do something like this:
$> scp -rp /var/www/html/somedir/* 192.168.1.100:/var/www/html/somedir/.
This way with the p flag you tell the command to copy the files and preserve permissions, ownership, date stamps. The r flag creates subdirectories as needed and recursive copies.
Just like any other command you can place several lines of scp in a script to automatize, but to avoid password use ssh generated certificates among servers.

How to set read/write permissions in Apache on a Windows computer

I am building a web page with Apache2.2, PHP5.2.2 on a Windows XP computer in a localhost configuration. I'm developing app/pages/submitProcessor.php to validate photo uploads from users. It validates file existance, size, mime type, drops unwanted characters, assigns a new file name, and uses move_uploaded_file() to store the file in app/uploads. I read in PHP - Question about uploading & uploaded image file that this photo storage file should be write only from app/pages/submitProcessor.php and it would be nice if it were read only from code within app/pages.
I've read a lot of info, and being pretty new to this, I still don't understand how to set read/write permissions in Windows XP in something resembling my configuration. I'm completely confused by 777, 775, 755, php.ini vs httpd.config and linux vs Windows. I'm also not comfortable with command line stuff, and would prefer to edit the appropriate file, if that is possible. How do I configure Apache so any file in app/uploads will not be executable, will write only from app/pages/submitProcessor.php, and read from app/pages/display or others in app/pages . . . or at least I'd like to get close to that. Not executable in the app/upload directory is pretty important to me.
If you are running Apache as a Service (the default setup for stand-alone & WAMP Apache installations), then that Apache Service is running under Windows' LocalSystem account.
This Windows account already has full read and write ('777') permissions on most local paths.
So when you read instructions to chmod 777 this, chmod 755 that, etc, ... you can ignore those parts of the instructions. Apache already can read-from and writeout-to those directories (unless it's a UNC path of a networked drive).
Setting File Permissions with chmod on Windows for Apache and PHP
I'm not 100% positive if that was the account on Windows XP (it is on Vista and up), but the behavior was the same.
In Windows, access to directories/folders is set by right clicking the directory, and reading through the selections provided by the various tabs to set access and specific uses of the directory. Its not as fine-grained as CHMOD, but it was good enough for my purposes at the moment.

Why can't I download files uploaded with PHP?

I have created a custom CMS with PHP and it uploads files to a directory with 777 permissions on it. When the files are uploaded they are given 600 with apache being the owner, therefore I can't download them through FTP as the main FTP user.
Anybody have any ideas? I have tried changing the permission but don't have rights due to the owner being apache.
You cant chmod the files, but 'apache' can: after uploading an moving the file,change the permissions in the same script. As it is run by apache, it is allowed to do so.
http://php.net/manual/en/function.chmod.php
For uploading files it is important to note that uploading files without explicitly setting permissions after is a bad practice.
I would take the link Nanne provided and begin to add that to your upload script. This will ensure that the files are given the appropriate permissions for each situation you will need them.

How to change uploaded file permissions for new files automatically

I recently moved a wordpress site from media temple's gs to their dedicated virtual server.
The file structure changed when I upload files. The permissions automatically upload as 644 and I'd like to change this. Where should I look to change this, the php.ini file or somewhere ont he server settings? It uses plesk.
You're going to want to find a way to change your umask. You might have to talk to your server administrator about it, if you don't have shell access.

Categories