Using the << here operator for FTP usage and data transfer

FTP is a commonly used <indexentry content="here document:<protocol to transfer data on websites. FTP stands for File Transfer Protocol. The following steps show the <indexentry content="here document:<usage of FTP and data transfer:

  1. Write the here_07.sh script:
#!/bin/bash 
# Checking number of arguments passed along with command 
if [ $# -lt 2 ] 
then 
  echo "Error, usage is:" 
  echo "ftpget hostname filename [directory]." 
  exit -1 
fi 
hostname=$1 
filename=$2 
directory="."        # Default value 
if [ $# -ge 3 ] 
then 
  directory=$3 
fi 
ftp << End_Of_Session 
open $hostname 
cd $directory 
get $filename 
quit 
End_Of_Session 
echo "FTP session ended." 
  1. Save the file, give the permission to execute, and ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.