Lets assume that password of my server is Abcd$1234

I am trying to ftp a file from other server to my server using the following in shell script

ftp -inv (IP) << EOF
user Username Abcd$1234

"lines to ftp file"


I am unable to ftp. I tried replacing password as Abcd\$1234 and also "Abcd\$1234" but no use.

But I am able to login to my server without ftp (just to verify whether password is valid or not)

Can anyone please help. I want to use $ in my password at any cost

  • I tried it. But its not working – Shreyash Aug 15 '14 at 13:03
  • 1
    You can use <<'EOF' newline and close it with 'EOF' – Valentin Bajrami Aug 15 '14 at 13:09
  • 1
    @val0x00ff, using <<'EOF', you still use just EOF to close. – glenn jackman Aug 15 '14 at 13:22
  • @glennjackman nice catch. I just edited the answer. The last EOF should indeed not contain single quotes. – Valentin Bajrami Aug 15 '14 at 13:23
  • I would advice against storing the password in plain-text in a script. – Bernhard Aug 15 '14 at 13:31

Here documents. cat <<EOF followed by several lines of text, followed by the literal string EOF on a new line, NOT indented. The portion between the EOFs is passed to the command as standard input. If 'EOF' is 'quoted', substitutions WON'T be done; otherwise they are. See <<- for the indented variety.


    ftp -inv (IP) <<'EOF'
    user Username Abcd$1234

    "lines to ftp file"


should work and will treat $ as literal $. It will not reference it as being a variable.

  • I am still facing the same problem. 331 Password required for oracle. 530 Login incorrect. Login failed. 530 Please login with USER and PASS. 530 Please login with USER and PASS. 530 Please login with USER and PASS. 221 Goodbye. – Shreyash Aug 15 '14 at 13:31

instead of here documents, try something like this:


    exec 6>&1
    ftp -nvi >&6 2>&6 |&

    print -p open Server
    print -p user User $pw

    "lines to ftp file"

    print -p bye
  • syntax error near unexpected token `&' – Shreyash Aug 15 '14 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.