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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.