FTP file upload using shell script on LINUX/UNIX
FTP file upload is not a big task. It is easy to upload files from the command line as well as using free X window-based FTP clients such as gFTP. However, it is often required to automate FTP file upload tasks using some kind of script such as bash. Below is the subroutine in bash that I often use to upload log files to the 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 sessions or FTP file upload tasks? If yes then let everyone know in the 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.
Weekly Newsletter
Never miss an update. Subscribe and follow to stay informed.
Delivered Every Tuesday.
Delivered Every Tuesday.
Thank you! You have successfully subscribed to our newsletter.
We hate spam too, we will never share your details.
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