FTP file upload using shell script on LINUX/UNIX
FTP file upload is not a big task. It is easy to upload file from command line as well as using free X window based FTP clients such gFTP. However, it is often required to automate FTP file upload task using some kind of scripts such as bash. Below is the subroutine in bash that I often use to upload log files to FTP server.
---------------------------------Start----------------------------------->
###Accepts following arguments
### 1. FILE TO UPLOAD
### 2. HOSTNAME TO FTP
### 3. USER NAME
### 4. USER PASSWORD
###
uploadLogs(){
FILETOUPLOAD=$1
HOSTNAME="$2"
USERNAME="$3"
PASSWORD="$4"
ftp -dvin $HOSTNAME <<EOF
quote USER $USERNAME
quote PASS $PASSWORD
mkdir $PLATFORM
cd $PLATFORM
binary
hash
put $FILETOUPLOAD
quit
EOF
}
<--------------------------------End------------------------------------
Bash subroutine above is almost self explanatory. Do you use any other mechanism to automate FTP session or FTP file upload task? If yes then let everyone know in comments below.
Never miss an update. Subscribe and follow to stay informed. Delivered Every Tuesday.
We hate spam too, we will never share your details.

Mandar Pise
Opinions expressed by techsutram contributors are their own. More details
Mandar is a seasoned software professional for more than a decade. He is Cloud, AI, IoT, Blockchain and Fintech enthusiast. He writes to benefit others from his experiences. His overall goal is to help people learn about the Cloud, AI, IoT, Blockchain and Fintech and the effects they will have economically and socially in the future.
Useful ftp script...most versions are crap but this one works fine!
ReplyDeleteYes worked great. Helped me automate a rather boring monthly backup upload.
ReplyDelete