How to Configure the ftp Server for Uploading the file?

  • When we are trying to put the files into the server we will get the permission denied message, which means that the ftp server is configured to download the files from the server not to upload the files from the server.
[root@sys2 ~]# ftp 192.168.1.5
Connected to 192.168.1.5 (192.168.1.5).
220 (vsFTPd 2.2.2)
Name (192.168.1.5:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> !ls
anaconda-ks.cfg      install.log          ithonors2   Pictures   Templates
core.2841            install.log.syslog   ithonours2  Public     Videos
Desktop              ith                  ithonours3  sapbasis
Documents            ithhard              ithsoft     sapbi
Downloads            ithonors             Music       sapmb
ftp> put ithsoft
local: ithsoft remote: ithsoft
227 Entering Passive Mode (192,168,1,5,186,79).
550 Permission denied.

 

  • Now we have to configure the ftp server for uploading the files as well as downloading the files.
  • Open the configuration file and uncomment the anon_upload_enable=YES.
[root@sys1 ~]# vim /etc/vsftpd/vsftpd.conf
24 # Uncomment this to allow the anonymous FTP user to upload files. This only
25 # has an effect if the above global write enable is activated. Also, you will
26 # obviously need to create a directory writable by the FTP user.
27 anon_upload_enable=YES

 

  • Restart the service for uploading the files.
[root@sys1 ~]# service vsftpd restart
Shutting down vsftpd:                                                [ OK ]
Starting vsftpd for vsftpd:                                          [ OK ]

 

  • Now connect to the ftp server from the remote machine and try to upload the files to the server.
[root@sys2 ~]# ftp 192.168.1.5
Connected to 192.168.1.5 (192.168.1.5).
220 (vsFTPd 2.2.2)
Name (192.168.1.5:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

 

  • Now choose the file which you are going to upload to the server using >!ls command.
ftp> !ls
anaconda-ks.cfg  install.log            ithonors2    Pictures    Templates
core.2841        install.log.syslog     ithonours2   Public      Videos
Desktop          ith                    ithonours3   sapbasis
Documents        ithhard                ithsoft      sapbi
Downloads        ithonors               Music        sapmb

 

I have chosen the file “ithsoft”.

  • Upload the file using the put command as follows.
ftp> put ithsoft
local: ithsoft remote: ithsoft
227 Entering Passive Mode (192,168,1,5,179,221).
553 Could not create file.
ftp>

 

We may notice the error could not create the file. This is due to the selinux.

  • Now go to the server and check the Booleans for ftp as follows.
[root@sys1 ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
ftpd_connect_db --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off

 

Set the above highlighted Boolean value as on

  • Setting the Boolean value as follows.
[root@sys1 ~]# setsebool -P allow_ftpd_anon_write on
[root@sys1 ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --> on
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off

 

  • Now give read and write permission to the shared pub directory as follows.
[root@sys1 ~]# cd /var/ftp
[root@sys1 ftp]# ls -ldZ
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 .
[root@sys1 ftp]# ls -ldZ pub
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 pub
[root@sys1 ftp]# chcon -t public_content_rw_t pub
[root@sys1 ftp]# ls -ldZ pub
drwxr-xr-x. root root system_u:object_r:public_content_rw_t:s0 pub

 

  • Now login to the client machine and try to upload the files.
[root@sys2 ~]# ftp 192.168.1.5
Connected to 192.168.1.5 (192.168.1.5).
220 (vsFTPd 2.2.2)
Name (192.168.1.5:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> !ls
anaconda-ks.cfg  install.log            ithonors2    Pictures    Templates
core.2841        install.log.syslog     ithonours2   Public      Videos
Desktop          ith                    ithonours3   sapbasis
Documents        ithhard                ithsoft      sapbi
Downloads        ithonors               Music        sapmb

 

  • Now select the file to upload, I selected the above highlighted file. Upload the file using the put command.
ftp> cd pub
250 Directory successfully changed.
ftp> put ithsoft
local: ithsoft remote: ithsoft
227 Entering Passive Mode (192,168,1,5,109,235).
150 Ok to send data.
226 Transfer complete.
16 bytes sent in 0.022 secs (0.73 Kbytes/sec)

 

  • Check the file is success fully transmitted or not.
ftp> ls
227 Entering Passive Mode (192,168,1,5,246,153).
150 Here comes the directory listing.
-rw-r--r--   1   0     0     0     Mar   09   07:16   ithonours1
-rw-r--r--   1   0     0     0     Mar   09   07:16   ithonours2
-rw-r--r--   1   0     0     0     Mar   09   07:16   ithonours3
-rw-------   1  14    50    16     Mar   10   08:44   ithsoft
226 Directory send OK.

 

Topics Summary