»  Home  »  Web Technologies  »  FTP and Understanding File Permissions
FTP and Understanding File Permissions
By Eddie Machaalani | Published 12/7/2005 | Web Technologies | Rating: ratingfullratingfullratingfullratingfullratingfull Unrated |
FTP and Understanding File Permissions

Introduction
Are you wondering what FTP is and how you can use it to upload/files from your site quickly and easily? Would you like to know how to set permissions on files and folders? If so, then this tutorial is for you.

This tutorial started out as a simple primer for newbies that need to learn a few specifics about FTP technology and how to use it, but I've also inserted some interesting stuff about FTP permissions syntax that some of you seasoned guys probably don't know or just never got around to looking at. Things that make you go 'hmmm' and 'wow, I get it… cool.'

I know some of you may be convinced that you have sufficient tools to upload and download files using your built in FTP client in your HTML editor, but I will show you an example of a freeware FTP client that will give you more control over the advanced features of your site, allowing you to upload and install scripts properly, rather than just uploading HTML files.

Please note: This permissions tutorial applies to UNIX/Linux-based servers only and although Windows does have a permission system, it's different and cannot be set by anyone using an FTP client.

What is FTP?
FTP stands for File Transfer Protocol. In easy to understand terms, FTP is the way that computers talk to each other to transfer files. It's quicker than transferring a file by email or on a disk. It's direct access to the space that you are transferring files to.

Ok, so how do we get connected in order to transfer files using FTP? Good question. We need a 'client' or a browser that speaks 'FTP'. We need an FTP client.

Getting an FTP client
There are tons of FTP clients out there, and some are even built into your HTML editors to allow you to upload your files to your web space. Most of these only transfer files to and from the space that you are connected to. While, in most cases, this is sufficient for updating the content of a website, they just don't cut it as far as I'm concerned.
You need something that will allow you to change permissions at the very least. When you start to get a little more involved you might want to explore some FTP commands and also use SFTP or SSH (Secure FTP or encrypted connections).

I found FileZilla was a decent choice because it has the ability to allow you to grow a little. You can download a copy from the current project page for free at http://filezilla.sourceforge.net/

Connecting to your website
In order to connect to a web site using FTP, you must have 3 things: A server/FTP address, a username and a password.
This will then connect you to the folder on the computer that the username is allowed to access. This will usually be where your website domain is pointing when you view it from a browser.



To connect using FileZilla, you can simply use the quick connect bar at the top of the program to enter your FTP server address, username and password. Don't worry about the port number, it simply defaults to 21. If you must use a specific port for FTP then you can enter it there.



Once you are connected you should see a list of files (if there are any) or folders in your remote directory listing. Sometimes you will connect just outside your viewable website folder which might be public_html, www, htdocs or httpdocs. If you don't know where your viewable website folder is, then you should ask your host – just email them and say something like "Look, I'm new to using FTP, and I need to know which folder my website is stored in so I can upload files to my site". That should be enough for them to tell you where it is.

Another way to see where your viewable folder might be is to check the email that was sent to you by your host when you signed up. If you were able to get the FTP details, then you might see a path that contains your website directory. Eg. /home/www/username/public_html. The last thing to remember about your viewable website directory is that you cannot access it from your domain using the actual folder name. For example, if your domain is www.yourdomain.com and your website folder is "public_html", then you cannot access www.yourdomain.com/public_html because it is already pointing directly at the folder when you type www.yourdomain.com – you don't need to add the folder name on the end.

Here's an example site that I logged into using FileZilla.



Uploading and Downloading Files
If all is well and you have connected via FTP to your website directory, then you should be able to look on your local drive on your computer for a file that you want to place on your website. The best choice at this stage would be a normal HTML file that is already viewable locally within a browser. So instead of this address - C:Documents and SettingsUser1My Documentsmyhomepage.htm, you will upload the file and then access it from your domain name like this- http://www.yourdomain.com/myhomepage.htm

Upload a HTML file via FTP and you will be able to see it through your browser. You will have published a file that anyone on the Internet can see. The earlier diagram shows connecting to the same space using a browser and an FTP client.

What are file permissions? Why do we need them?
File permissions are necessary to protect and to instruct the server about how to handle certain files. They can be set using raw FTP commands, but the easiest way to set them is using an inbuilt tool from your FTP client. This is where some FTP clients do not support the changing of permissions on files. One good example is the built-in FTP client in Dreamweaver, which will only allow you to set permissions using a specific raw FTP command. If you have multiple files and folders to set permissions on, typing the FTP command multiple times would become tedious.

It is a good idea to become at least a little familiar with what permissions are used for what purpose. The reason for this is that most scripts will actually need certain permissions to run. If they are simply uploaded as normal by say, Dreamweaver, they will inherit 'normal' permissions by default, but it may not be suitable in order to actually 'run' or 'execute' the commands that are inside the script. Most default permissions will only allow you to read a file, which will unfortunately not be enough to run a script.
The most common permission required to run a script is CHMOD 755 (-rwx r-x r-x)

What's CHMOD?
CHMOD stands for Change Mode and simply means that you are changing your permissions on the file or folder. "CHMOD" is also a UNIX command that is used in code and through the command line to change permissions on files and folders.

For example, in PHP it's used like this: chmod("/path/to/filename", 0755);

Types of permissions for different user groups
There are three types of permissions to set on folders and files on UNIX servers – Read, Write and Execute permissions. There are three distinct groups that are affected with these permissions to allow you to control who has access to the file or folder.

These groups are as follows:
The owner of the file - usually whoever uploaded it, or whomever created it.
The group – usually other registered hosting users on the actual server or common resources that are setup to run under this permission group.
The public – this is the public or Internet user.

So each group has three settings or switches, to allow you to control their access based on whether you want them to read, write or execute the resource that you are setting permissions on. For example, you can allow the owner group to read and write to the files, while the group and public can only read.

Setting Permissions in FileZilla
FileZilla will allow you to change the file permissions or "attributes" as this program calls them, on files and folders. You can even choose multiple files and folders in the same window view to change multiple permissions at the same time.

Setting a file or folder permission in FileZilla is easy. You simply check the box to turn that setting on, like a switch. Select a file, then right click on it. A menu will appear and you will need to choose "File Attributes".



A popup will appear with options available for all permissions on each group. You simply have to check the boxes or enter the numbered permission that you require in the box provided.



FTP Notation - text and number versions
As you saw above, FileZilla sets permissions using checkboxes to allow you to quickly and visually turn the switch on for a specific permission for each user. However, you may come across some weird looking notation like the following:

"-rwxr-xrwx" or someone may tell you to use the permission, CHMOD 757 on a file to allow it to run properly. These are just two ways to represent the same thing.

Let's explore the first text based notation. It has a dash, then 9 characters after it. The first dash could be a 'd' to represent a directory, or a dash to represent a file. Sometimes it's just left out and isn't even there.
The next 9 characters represent the three groups – owner, group and public in order as well as the permission for each. Look at the diagram below compared to your checkbox model of applying permissions.



Once you know the syntax of the FTP permission, you can quickly read it and then interpret what it means in terms of actual permissions for your script or file.
You can use the above diagram until you know them off the top of your head.
Some scripts don't tell what CHMOD to use numerically, so it's great to be able to interpret the permissions from text notation.

The number notation is quite interesting actually and it has an almost algebraic feel to it. The actual numbers used are based on the bits, which I won't get into, but basically each CHMOD number is broken up into 3 numbers in order of owner, group and public and the permissions for each group are based on it's total sum. It's pretty hard to explain in words, so I'll have to show you the numbers used to represent the read, write and execute attribute to allow you to understand more fully.


This would mean the owner and public can read, write and execute, while the group can only read and execute.
Let's break this number into columns. The first 'column' is the owner, the second 'column' is the group and the third 'column' is the public.

Now we'll learn where these numbers are coming from and what they mean.
In FTP number notation, "Read" is represented by the number 4, "Write" is represented by the number 2 and "Execute" is represented by the number 1.
The actual permission for each group is based on the total number for each column. A combination of the three permissions will create a different total for that column, which represents the permission for that group.

Look at the following table and what that number represents. I will also explain with representation why that total means that particular permission.

                                                                       
Number

Permission

Text display
0

None

---
1

Execute

--x
2

Write

-w-
3

Write, execute

-wx
4

Read

r--
5

Read, execute

r-x
6

Read, write

rw-
7

Read, write, execute

rwx


User can read only is represented by a 4. You are simply turning on reading by the 4 that represents the read attribute.
User can write only is represented by a 2 and user can execute only is represented by a 1.

User can execute and write is represented by a 3.
Eg. since execute = 1 and write = 2
1 + 2 = 3 which is the same as saying 'execute' + 'write' = 3
The server knows to allow this user to execute and write

User can read and execute is represented by a 5.
Eg. since read = 4 and execute = 1
4 + 1 = 5 which is the same as saying 'read' + 'execute' = 5

User can read and write is represented by a 6.
Eg. since read = 4 and write = 2
4 + 2 = 6 which is the same as saying 'read' + 'write' = 6

User can read, write and execute is represented by a 7
Eg. since read = 4 and write = 2 and execute = 1
4 + 2 + 1 = 7 which is the same as saying 'read' + 'write' + "execute" = 7

So for each column, which represents each group, you simply enter the permission that you want for that group based on the number notation explained above.

Conclusion
So, there's some little FTP tips for those of you who might have had trouble installing scripts in the past. It might have been a permissions problem, so you should definitely revisit that script and it might just work now.

Hopefully I have given you some insight into the FTP technology and hopefully you will start using FileZilla or a similar FTP application that will give you more control over your websites, and allow you to install some scripts for better functionality on your site.

Please note: This permissions tutorial applies to UNIX/Linux based servers only and although Windows does have a permission system, it's different and cannot be set by anyone using an FTP client.

13 Responses to "FTP and Understanding File Permissions"


 
Anne Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 29 Apr 2006 8:28:46 PM CDT
THANK YOU! I have been struggling for a week with how to set file permissions using Filezilla, and until coming across your article, I had no idea that it was actually the "file attributes." I also have a much better understanding of the logic behind permissions, and what everything means.

 
Fred Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 08 Jun 2006 10:27:32 AM CDT
Thank you very much for the very helpfull information. I didn't know that you could set file permissions with FileZilla.

 
Quark Rating: ratingfullratingfullratingfullratingemptyratingempty Unrated
said this on 23 Aug 2006 10:56:11 AM CDT
Excellent explanation. From A to Z.

 
Luke Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 26 Aug 2006 10:40:49 AM CDT
Thanks heaps!! Was limited to the work i could do because every time i modified my CGI in Windows and uploaded to unix server i would loose execute permissions, hence it would not serve to the internet, and i would loose the ability to debug. Now i can do it easy. Thanks...

 
Val Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 06 Feb 2007 1:20:39 PM CDT
Can you tell me why when I chmod 666 a file or directory, it disappears from view. When I try to overwrite (delete, rename, or recreate) it, it gives me an error 550: No such file or directory. Thanks!

 
Robert Rand Rating: ratingfullratingfullratingfullratingemptyratingempty Unrated
said this on 27 Feb 2007 1:03:06 PM CDT
One thing you left out is that to be able to change attributes you must connect in Active and not Passive mode. If you connect in passive mode the file attributes in the right click pull down is greyed out...regards.

 
Tobey Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 06 Apr 2007 10:25:56 AM CDT
Excelent explanation. Thx.

 
Steve Thomas Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 06 Sep 2007 12:32:51 PM CDT
Great stuff!!!!!

 
Luis Danilo Ruiz Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 28 Nov 2007 11:37:53 AM CDT
Thnx, I was googling a full week, 'til I found this single phrase in your article. "Please note: This permissions tutorial applies to UNIX/Linux based servers only and although Windows does have a permission system, it's different and cannot be set by anyone using an FTP client."
I've learned this: Doesn't matter if you use FileZilla FTP Server in a Windows Server, You can't change any file permissions.

 
Ramkumar Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 21 Dec 2007 8:18:45 AM CDT
Fine Article

 
John Galantini Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 17 Jan 2008 6:30:48 PM CDT
Very helpful. My limited understanding of the File Permissions has been greatly expanded. Thank you for the advice.

 
abe Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 09 Apr 2008 3:03:01 PM CDT
great help guys !

 
Marius the Wanderer Rating: ratingfullratingfullratingfullratingfullratingfull Unrated
said this on 26 Apr 2008 9:50:54 PM CDT
Thank you *ever* so much! I used to know this stuff in my UNIX-weenie days. Fifteen years later I volunteered to be the Webmaster for my group and found I'd forgotten most or all of it. You have saved me several moments of cognitive dissonance and potential acute embarrassment!



Rate this article and leave a reply:
1 2 3 4 5
Poor Excellent
Your Name *: Email (private) *: Website:
Please copy the characters from the image below into the text field below. Doing this helps us prevent automated submissions.
Security Code: img

Web designers: Learn how to attract more clients and profit like the big guys. Subscribe to our newsletter.