Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Please reason I use a generic password is because all users need something simple to login by otherwise they will not bother.
Now my question and issue is:
I am wanting to be able to have users upload their files and have read only attributes for other users so another user cannot delete the file. My web host offered 755 as permissions set on the ‘ftp’ folder as solution and this doesn't work as I have had another user login and delete my test files with 755 and the same with 700.
So Person A logs in with the details above and uploads a file called TEST.txt. Then person B logs in (from another computer and IP of course) logs in with the details above and uploads a file called IMAGE.jpg
Currently person B can see person A's file TEST.txt and then person B can deletes it and visa versa. This is not what I want, I do not want person B to come along and delete person A's files or the other way around..
I have had another person suggest to me the following, that persons message to me is:
To set up a cron job with a script command to add read only attributes once the file is uploaded to my ‘ftp’ folder so any user that logs in can see the files but they cannot delete them.
I have added a screenshot of my CRON JOB cpanel view. NOW is this possible that someone knows a script to make a file have READ ONLY attributes once it is fully uploaded to my ‘ftp’ folder.
Also apart from the command script the other options are how often from the common settings dialog box and what needs to be added to the command to allow it to operate in the ‘ftp’ folder.
Again the FTP is mydomain//home/mp/public_html/aoe2hdozclan.com/ftp
The users will be uploading video files so they may take 30-60 minutes approx and will the common settings affect the upload or will they just keep executing on the files regardless?
I hope someone could please help me out on this one as it’s a very important factor on this site for our users/
Hi, if you want to run the command each minute for example, put */1 for Minute, and * for the others. The command is chmod -R a=r /home/mp/public_html/aoe2hdozclan.com/ftp/*.
But I don't think cronjobs are a good idea. For example someone could delete a file uploaded less than a minute ago with those settings.
Hello ra.amri, thank you so very much for this, can I ask you that is exactly my issue, I simply do not want people to delete the other peoples files, is there a way that I can be alerted of a new file appearing in the folder, like via email....this way I can go and retrieve it asap....is this possible at all, I simply need a quick solution that I can retrieve the file ASAP
Thank you very much for your help and I hope you could answer this new query
Many thanks in advance
it does change the file to 444 which is great, the log is as follows:
I understand the permission denied as that folder has 000 as the permissions
CAN I ASK AGAIN, is it possible in a cron job to alert me when a new file appears in the ftp folder, I am more and more thinking that this may be the solution because I can retrieve it within a couple of minutes or 5 minutes from arriving???
If they're all sharing a login area, you might as well use the anonymous option anyway.
More specifically, see 22.5.6. File Transfer Options https://www.centos.org/docs/5/html/D...ftpd-conf.html to change the ownerships after upload.
Use chown_uploads, chown_username options.
Oh, dear I do not have those options as it needs a password according to this screenshot, I am not sure about that page and where to add these options......I am not a coder and not sure where to start but the other option could a file alert me as to when it arrives or how do I actually code the anonymous way?
Doing a cron job to set the files to be readonly would only be effective if you changed the user with chown. I do not recommend this. Not only will you be *regularly* chowning possibly a large amount of files as the directory grows but you'll be faced with the fact that there will always be some delay that files can be affected by other users until the cron job runs.
I recommend you set up an FTP Staging directory where your users upload to a staging directory and upon the upload finishing the FTP server automatically moves the files to another directory. This way only the staging directory is read/write for the user and any other directories are not. This would require you modifying the configuration of the FTP server itself to accomplish this. What FTP server are you using?
Its just a standard FTP server through my cpanel...where you have to set password etc.
Is it possible using the cron job to have another folder next to the ftp folder which is not an ftp folder but the cronjob script moves the files to that folder after they are downloaded, is this possible at all, then no one will be able to move the file once it has arrived because the script has moved the file, is that possible at all...
By the way, thank you so very much for helping me out here, no one else has been able to assist me, this is for our Gaming Clan and a lot of people are asking so again thank you
Sure you can. Let's call the staging directory "upload".
For example here's your directories:
/home/mp/public_html/aoe2hdozclan.com/ftp
/home/mp/public_html/aoe2hdozclan.com/ftp/upload
Make the ftp directory read only for the user and make the upload directory write only (with no ability to read). Replace the "aoe2hdozclan@mdexter.com" with the proper user that requires ownership of these directories.
Now a user shouldn't be able to upload files to the ftp directory but they *can* upload files to the 'upload' directory.
Create a script which can be executed by a cron job. Let's call it /usr/local/bin/movefiles.sh
Code:
#!/bin/bash
cd /home/mp/public_html/aoe2hdozclan.com/ftp/upload
#If there are no files then simply exit
if [ "$(ls -1 | wc -l)" -eq "0" ];then
exit
fi
#there must be files since we've gotten this far so move them all one directory up.
mv * ../
Now create the cron job that runs every minute. See man 5 crontab.
WOW, this works absolutely perfectly, thank you thank you so very very much....that is awesome, i still havr the issue of only being able to have the permissions on the ftp and the uploads folder at 700 each otherwise I get an email permission denied
but it is working, and thank you so very much
---------- Post added 04-25-13 at 09:01 PM ----------
WOW, this works absolutely perfectly, thank you thank you so very very much....that is awesome, i still havr the issue of only being able to have the permissions on the ftp and the uploads folder at 700 each otherwise I get an email permission denied
How would you apply that to files with unknown inodes (i.e. they don't exist yet because they will be uploaded)? I've used something like incrontab to monitor the inodes on existing files but I've yet to find a good inotify solution for keeping track of folders updating. I'm curious to know how it would be done if it can.
*EDIT* after reading the inotifywait man page more closely I realize it is a command line tool and is able to monitor directories. Pretty cool. Learn something every day.
I have to say that this overall is the perfect solution and again I want to say thankyou very much for all of your awwesome help as you have solved my issue whilst others could not!!!
Again many thanks indeed and the folders operate as intended, love even testing them out......perfect stuff.
If you are in practice using my original "movefiles.sh" script then one thing I should have accounted for (nobody is perfect right?) is the possibility that a user uploads a file with a duplicate file name. You have two options to handle that.
Creating a backup copy for each file (so duplicates will move into a new file name).
Code:
mv --backup=numbered * ../
Or force the script to overwrite existing files of the same name.
#!/bin/bash
cd /home/mp/public_html/aoe2hdozclan.com/ftp/uploads
#If there are no files then simply exit
if [ "$(ls -1 | wc -l)" -eq "0" ];then
exit
fi
#there must be files since we've gotten this far so move them all one directory up.
mv * ../
Where would the new addition of
mv --backup=numbered * ../
Where would that fit into the above script......sorry, I like the option of the ability to rewrite incase they do upload two with the same name, just need to know where to put your new snippit into?
Will see how it goes, again thank you so very much
_______________________________________________
Would I be pushing the limits of the cron job, does it have the ability to send out an email to an email address with a custom message at all?
or is this something not capable of the cron job, if so it would be awesome to send out an automated message to the person who uploaded the file with a custom message?
Again if not, not to worry as you have been ever so helpful
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.