FTP a file using Shell Scripting (Help needed)

the requirements is to have a linux script which connects to a windows machine using ftp command and check for a flag file
if found copy a .csv file into current machine.

Using Perl

use Net::FTP
my $flagFile="flag.file";
my $ftp = Net::FTP->new("host") or die "cannot connect \n";
$ftp->login("user","passwd") or die "cannot login \n";
my @list=$ftp->ls(/file/path/);
if (grep {$flagFile eq $_ }@list) {
  $ftp->get("/file/path/file.csv") or die "get failed \n";
}
$ftp->quit;
#!/bin/sh

LOG=/xx/xx/xx/xx/xx/xx/xx

export day=`(date +'%m%d%y_%H%M_')`
set -x

PATH=$1
PATH1=$2
FILE=$3
FILE_T=$4



echo "FTP Started "  >$LOG/$FILE.log
/usr/bin/ftp -inv xx-xxx-xx 221 >>$LOG/$FILE.log <<EOF
user anonymous xxx@xx.xx.x
binary


cd $PATH

mget $FILE
mget $FILE_T

delete $FILE_T

quit

EOF




cd /xx/xx/xx/xx/xx/xx/xx

chmod -f 777 xxxx*.*


if [ -f $FILE_T ]
then
       
	echo "$file found."
             
else
	echo "$file not found."
fi

rm -f $FILE_T

-----------------------

error

+ chmod -f 777 xxx.csv xxxx.flag
./GET_FILE_FTP_QA.sh: line 44: chmod: command not found
+ '[' -f xxx.flag ']'
+ echo ' found.'
 found.
+ rm -f xxx.flag
./GET_FILE_FTP_QA.sh: line 58: rm: command not found

when i give chmod or rm it says command not found

The PATH shell variable has a very special meaning in any shell based on Bourne shell syntax. It is used to specify a list of directory that will be searched to find utilities that are being executed by your script when the commands used to execute those utilities do not you absolute pathnames.

So when you execute the command:

PATH=$1

on line 8 in your script, you create a problem that causes your script to fail 36 lines later. Choose a different variable name and change your script to consistently use that revised variable name.

1 Like