Wednesday, January 14, 2015

FTP Automation

This post will just give you a brief about how you can use FTP.

Normally we can use FTP in below way which is a normal standard.

$ftp -v HOSTNAME
> user USERNAME PASSWD
> [get][mget][put][mput] file / files
>bye
$

here -v stands for verbose mode which gives you details about each steps of how ftp client internally communicate with the host to connect successfully.

After providing userid passwd for to connect host, either you can pull/place the file/files. If you are dealing with single file then you can use get/put, for multiple files mget/mput.

As I said this is a standard way to do it, but how the industry use it.
Industry required, 
1. They don't want to provide userid/passwd, since it will be visible or security threat.
2. Make the FTP process automated
3. I don't want to provide userid / passwd while connecting to remote host.

Now how you can achieve this.
If you are going to connect xyz.com from your home a/c e.g. /home/vaibhav.
create .netrc file under /home/vaibhav/ directory.
Open file .netrc in any editor or vi editor and add below contents

machine xyz.com login your_userid password your_passwd 
Save the file and try the ftp again
Surprisingly it will directly connect you host xyz.com without providing userid/passwd

Industry standard discuss later is used is shell scripting also which makes automated stuff lot more easier.

I hope this is informative to you.

No comments:

Post a Comment