Tuesday, March 16, 2010

Secure FTP the files from unix to windows

Securing FTP in shell scripts using .netrc
Often we use FTP in the shell scripts and for security reason it is advisable not to store username and password in the shell scripts.

Here I discuss how can we secure the FTP process and restrict sharing of username and passwords.

File .netrc in the $HOME directory allows file transfers in batch mode. This file stores the machine name, login and passwords. The FTP commands gets information from the file and connects to the FTP server.

Each record has the format:

machine machine_name login login_name password passwd
where machine_name, login_name, passwd refer to a system name with the login and password for that account on the machine
e.g machine xyz.server.com login anonymous password xyz123

There are following 2 ways to execute the FTP commands

1) Create a command file and store all the FTP commands in the file.
e.g. File command_ftp is created and saved. The file has following content

bin
cd /inbound
get abcd.txt
bye 

Write following code in the shell script

ftp xyz.server.com < command_ftp 

2) The FTP commands can also be stored in .netrc file as a macro and the commands will be executed with the FTP command.
The .netrc file content would be something like this

machine xyz.server.com login anonymous password xyz123
macdef bin
cd /inbound
get abcd.txt
bye 

For this case the shell script will have following ftp command
e.g.
ftp xyz.server.com

The other way of securing FTP is by using the sftp(secure FTP) commands which is a network protocol that provides file transfer and transfers file in a secure way.

Thanks & Regards,
Anto Joe Natesh I

No comments: