Auto File Transfer Via FTP Batch Scripts In Both Windows And Linux
There are many ways to automate file transfer between networked computer. In the good old days, we rely on the simple-to-use ftp client that implement ftp protocol (port 21) for file transfer.
Even now, there are still number of implementation here and there, that automate file transfer between networked computer via ftp protocol.
First, we target the ftp client of Windows platform – How to automate file transfer via ftp client in Windows XP / Windows Vista?
There are equivalent implementation in Linux / Unix too, but the syntax is quite different. So, let’s see how to create a Linux scripts to automate file transfer with FTP client in Redhat Enterprise4.

First, we target the ftp client of Windows platform – How to automate file transfer via ftp client in Windows XP / Windows Vista?
- Create ftp command template file with these sample command and give it a meaningful file name, e.g. walker-ftp.tpl
open ftp.walkernews.net user walker-login-id-here walker-login-password-here prompt mget *.* by
Understand the ftp command template:
- use the mandatory keyword
opento specify the target computer that the ftp client connect (open) to, e.g. ftp.walkernews.net
- use the mandatory keyword
userto specify the user ID to login the ftp server
- specify the password used to authenticate the user login ID specify in step (b)
- assuming login to ftp server is successful, this step onwards are the normal ftp client compatible commands.
For example, typeftpat Command Prompt and typehelpat the ftp prompt will display all the ftp client compatible commands. To get further help description of each ftp client command, typehelp command, e.g.help prompt
Thepromptkeyword is use to turn on (default) or turn off interactive prompting on multiple commands. For example, if you don’t want to answer Y or N when execute mput or mget command. Essentially, it’s identical to explicitly specify-ioption switch to the ftp client.
You can typeftp -?at Windows Command Prompt for more ftp client option switches.
- The
mget *.*ftp command is to get / download all files in the target directory on remote ftp server to the working directory of the local computer.
- at last, execute
byorbyecommand to end or terminate current ftp connection.
- use the mandatory keyword
- Now, you can type this single command to instruct Windows ftp client program to automate file transfer /downloading with all the ftp commands specify in the template.
ftp -n -s:walker-ftp.tpl
You can either run it at Command Prompt window, or create a ftp batch scripts (Windows batch file) for the command – just double-click the ftp batch file to execute!
There are equivalent implementation in Linux / Unix too, but the syntax is quite different. So, let’s see how to create a Linux scripts to automate file transfer with FTP client in Redhat Enterprise4.
- In the user home directory, create a hidden file called .netrc that contains these auto-ftp commands
machine 10.1.1.10 login walker-login-id-here password walker-login-password-here macdef init prompt mget *.* quit Leave one mandatory blank line here Leave one mandatory blank line here machine ftp.walkernews.net login walker-login-id-here password walker-login-password-here macdef init pwd quit Leave one mandatory blank line here Leave one mandatory blank line here
Understand the .netrc file content
- the keyword
machineis used to specify the target ftp host that the ftp client connect to
- the keyword
loginis used to specify the user login ID
- the keyword
passwordis used to specify the password used to authenticate the user login ID
- the keyword
macdef initis used to define the auto-ftp macro command that named as init (refer toman netrcfor more information)
- supposed the login authentication is successful, then the rest of lines after macdec init down to
quitkeyword are ftp client commands. Thequitis identical to thebyecommand.
- after the quit keyword, press ENTER twice to leave two empty lines! These two lines are mandatory syntax of .netrc file for auto-ftp. As of this .netrc sample file, I’ve another ftp server added right after the first two empty lines, and end the second ftp server with another two empty lines as well.
- the keyword
- Execute
chmod 600 .netrcto limit only read and write permission for the login user ownership only. This is a must in order ftp client to automate file transfer!
- Now, if you want to auto-ftp with ftp host 10.1.1.10, just type this command
ftp 10.1.1.10
and the Linux ftp client will automatically execute the series of ftp commands in .netrc file for the matching ftp host.
Similarly, you can typeftp ftp.walkernews.netfor auto-ftp file transfer with the second ftp host.
Custom Search







2010 •
[...] without encryption feature. Thus, password-less SSH login is extremely useful in writing secured shell scripts that need to automatically (non-interactively) login remote server and then initiates file transfer [...]
[...] password for authentication. But, how could I handle this interactive authentication process in Windows batch files or Linux shell scripts that scheduled to trigger file transfer between networked hosts on a daily [...]
very usefull tips. very knowledge full. please send me tips via mail. thanks