0

I have a bunch of files in a folder that I want to move into a new folder in an ftp server. I am able to log in to the ftp server with the following code but I get an error while trying to create and move the file into the ftp server after logging in.

Here $Nelement is the ftp server IP $protocol is ftp

#!/bin/sh

        cat $ftpFile | while read LINE
        do
                user=`echo $LINE | awk -F":" '{print $1}'`
                pass=`echo $LINE | awk -F":" '{print $2}'`
                protocol=`echo $LINE | awk -F":" '{print $3}'`
                Nelement=`echo $LINE | awk -F":" '{print $4}'`

                if [ "$protocol" = "ftp" ]; then
                        `$protocol -n $Nelement <<EOS
                        quote USER $user
                        quote PASS $pass
                mkdir -p $dir
                cd $dir
                mput $newFileName
                bye
        EOS`

                else
                        `$protocol $user@$Nelement <<EOS
                        bye
        EOS`
                fi
        done

The error that I receive is

+ '[' ftp = ftp ']'
sc.sh: line 38: warning: here-document at line 31 delimited by end-of-file 
(wanted `EOS')
+ Create directory operation failed. Failed to change directory. mput 
'testfile.txt?' '?Invalid' command
sc.sh: line 31: Create: command not found
Ashwin
  • 1
  • There's a number of errors here. Try pasting your script at http://shellcheck.net/ and see its diagnostics before asking for human help. – tripleee Feb 02 '18 at 06:09
  • The [useless `cat`](https://stackoverflow.com/questions/11710552/useless-use-of-cat) and having to split apart the input line with repeated Awk calls could fruitfully be avoided with `while IFS=: read -r user pass protocol Nelement; do ... done <"$ftpfile"`. The shell is actually pretty good at splitting input into tokens, you know. – tripleee Feb 02 '18 at 06:11
  • See also https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable – tripleee Feb 02 '18 at 06:13

0 Answers0