ashish_k
ashish_k

Reputation: 1581

checking for a file in ftp server through shell script

I've written a code in shell to retrieve the file of type "OLO2OLO_20170601_FATTURA.txt.zip" which is of current date. Below is my code:

#!/bin/ksh

DATE=`date '+%Y%m%d'`
FILE="OLO2OLO_$DATE_FATTURA.txt.zip"

/usr/bin/ftp -n 93.179.136.9 << !EOF!
user abc 1234
cd "/0009/Codici Migrazione"
get $FILE
bye
!EOF!

But I'm getting below error:

$ ./ftp_test1
Failed to open file.

Upvotes: 0

Views: 89

Answers (1)

Dima Chubarov
Dima Chubarov

Reputation: 17159

You have to put the variable name in curly brackets.

FILE="OLO2OLO_${DATE}_FATTURA.txt.zip"

An underscore is valid in a variable name. It is not a token separator.

Formally

name is a word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore.

Currently shell is trying to substitute a value for a variable with name DATE_FATTURA which is empty so your FILE variable becomes OLO2OLO_.txt.zip Such file probably does not exist on the remote server.

Upvotes: 1

Related Questions