Monday, 29 October 2012

How to use FTP in a shell script?

FTP is a standard protocol for file transfer. With FTP, files can be transferred to and from a remote host. Remote host has a FTP server installed on it which listens to FTP clients. FTP client is the program which communicates with FTP server.
Suppose that a user has an account on FTP server with username name and password pass.
Now, let's write a script to transfer a file from a remote host to local machine.

#! /bin/sh 
ftp -in host/ip<<END 
user name pass 
cd /var/myremotedir 
lcd /var/mylocaldir 
get file 
close 
bye 
END 
echo 'transfer completed' 

 In the above script, we are transferring file from remote directory /var/myremotedir to local directory /var/mylocaldir. cd is used to change directory at remote server. lcd is used to change directory at local machine. get is used to transfer file from remote directory to local directory. Similarly, we can use put to transfer file from local directory to remote directory. Note: Here cd, lcd, get are ftp commands and not unix commands. FTP server should be installed and listening on remote machine for FTP client to communicate. The username and password used by FTP client should be registered with FTP server.

For more info visit

1 comment:

  1. The casino at Wynn Las Vegas and Encore - JT Hub
    Results 1 - 12 of 1303 — Wynn 경기도 출장마사지 casino at wynn las vegas and encore resort encore resort 동두천 출장안마 encore resort encore resort encore resort encore 원주 출장안마 resort encore resort encore resort encore 영주 출장마사지 resort encore 여수 출장안마

    ReplyDelete