Enable ftp connection using proftpd

Feb 26, 2012 11:13 PM

Enable file transfer using ftp is not difficult task in linux system. After ftp server application installed, then check it: for example in slackware,
$ ls /var/log/packages/ | grep ftpd
proftpd-1.3.3e-i486-1
vsftpd-2.3.4-i486-1

After we make sure this application installed in the system, the first step is modify the file configuration. In this article i am choose proftpd, because it quite easy to configure. Using your favorite text editor, edit file /etc/proftpd.conf, modify the "servername" and "servertype".

ServerName                      "WAR49 FTP Server"
ServerType                      standalone

And then, save it and run ftp server application (with root previleges).

root@darkstar:~# proftpd
root@darkstar:~# ps -ef  | grep ftp

nobody    2878     1  0 21:37 ?        00:00:00 proftpd: (accepting connections)
root      2882  2669  0 21:37 pts/1    00:00:00 grep ftp

Untill this step, the server is ready for accepting connections. But we can also make user for this ftp activity.

root@darkstar:~# groupadd planet
root@darkstar:~# useradd -G planet -d /export/home/earth -s /bin/bash earth 
root@darkstar:~# useradd -G planet -d /export/home/venus -s /bin/bash venus

Command like useradd is not automatically create the home directory for user, useradd command just update contents of /etc/passwd file. So you must create it manually and give permission to the directory.

root@darkstar:~# mkdir /export/home/{earth,venus}
root@darkstar:~# chown -R earth:planet /export/home/earth/
root@darkstar:~# chown -R venus:planet /export/home/venus 

Both earth or venus directory has created. Then, giving user password for them.
root@darkstar:~# passwd earth
Changing password for earth
Enter the new password (minimum of 5 characters)
Please use a combination of upper and lower case letters and numbers.

New password: 
Re-enter new password: 
passwd: password changed.
root@darkstar:~# passwd venus
Changing password for venus
Enter the new password (minimum of 5 characters)
Please use a combination of upper and lower case letters and numbers.
New password: 
Re-enter new password: 
passwd: password changed.

Trying access to ftp server.
wardi@darkstar:~$ id
uid=1000(wardi) gid=1000(wardi) groups=1000(wardi)
wardi@darkstar:~$ ftp 192.168.2.103
Connected to 192.168.2.103.
220 ProFTPD 1.3.3e Server (WAR49 FTP Server) [192.168.2.103]
Name (192.168.2.103:wardi): earth
331 Password required for earth
Password:
230 User earth logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/export/home/earth" is the current directory
ftp> bye
221 Goodbye.

Untill this step, the ftp connection was succeed. Then, we have a scenario like this: Path /share is owned by user earth in group planet, this path (/share) want to be shared to user venus. So, in this case, user venus can read the path, only read. When user venus login into ftp server, the default directory is /export/home/venus. In this default directory would be create a symbolic link (shortcut) to /share that owned by user earth. So, by clicked this shortcut, user venus can access the /share directory.

As root user create /share directory and given to user earth.
root@darkstar:~# mkdir /share && chown -R earth:planet /share
root@darkstar:~# ls -l / | grep share
drwxr-xr-x   2 earth planet  4096 Feb 26 22:28 share

/share directory has 'rwx' permission for owner (earth) and has 'r-x' permission for group (planet). So, in this case, user venus is in the same group as user earth. So user venus has read permission to this directory. Then (as venus), go on to venus home directory, and make symbolic link (shortcut) to /share directory.

venus@darkstar:~$ ln -s /share the_share
venus@darkstar:~$ ls -l
total 0
lrwxrwxrwx 1 venus venus 6 Feb 26 22:34 the_share -> /share

Then, Check in FTP connection and login with venus user.
wardi@darkstar:~$ ftp 192.168.2.103
Connected to 192.168.2.103.
220 ProFTPD 1.3.3e Server (WAR49 FTP Server) [192.168.2.103]
Name (192.168.2.103:wardi): venus
331 Password required for venus
Password:
230 User venus logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
lrwxrwxrwx   1 venus    venus           6 Feb 26 15:34 the_share -> /share
226 Transfer complete

Then, go to the shortcut that would take you to /share directory.
ftp> cd the_share
250 CWD command successful
ftp> pwd
257 "/share" is the current directory
ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
-rw-r--r--   1 earth    earth           0 Feb 26 15:42 earth_data1.txt
-rw-r--r--   1 earth    earth           0 Feb 26 15:42 earth_data2.txt
226 Transfer complete

Then, get all file .txt in the /share directory to local system.
ftp> lcd ~/    
Local directory now /home/wardi
ftp> mget *.txt
mget earth_data1.txt? y
200 PORT command successful
150 Opening BINARY mode data connection for earth_data1.txt
226 Transfer complete
mget earth_data2.txt? y
200 PORT command successful
150 Opening BINARY mode data connection for earth_data2.txt
226 Transfer complete
ftp> bye
221 Goodbye.

Check on the local system to ensure that those file are downloaded perfectly.

wardi@darkstar:~$ ls *.txt
earth_data1.txt  earth_data2.txt

User earth can upload anything file to the /share directory due to /share directory has owned by user earth by ftp command.

wardi@darkstar:~$ ls font*
font  font2
wardi@darkstar:~$ ftp 192.168.2.103 
Connected to 192.168.2.103.
220 ProFTPD 1.3.3e Server (WAR49 FTP Server) [192.168.2.103]
Name (192.168.2.103:wardi): earth
331 Password required for earth
Password:
230 User earth logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /share
250 CWD command successful
ftp> pwd
257 "/share" is the current directory
ftp> mput font*
mput font? y
200 PORT command successful
150 Opening BINARY mode data connection for font
226 Transfer complete
176138 bytes sent in 0.0358 secs (4.8e+03 Kbytes/sec)
mput font2? y
200 PORT command successful
150 Opening BINARY mode data connection for font2
226 Transfer complete
89634 bytes sent in 0.0725 secs (1.2e+03 Kbytes/sec)

Check uploaded file in /share directory in server.

ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
-rw-r--r--   1 earth    earth           0 Feb 26 15:42 earth_data1.txt
-rw-r--r--   1 earth    earth           0 Feb 26 15:42 earth_data2.txt
-rw-r--r--   1 earth    earth      176138 Feb 26 15:51 font
-rw-r--r--   1 earth    earth       89634 Feb 26 15:51 font2
226 Transfer complete
ftp> bye
221 Goodbye.

Article list :