0

I'm using lftp to connect to a FTP server and am trying to cd into a specific directory, with that directory location saved as a variable, REMOTE_DIRECTORY.

I'm pretty sure this isn't working because of the spaces in the name of the folders, but I've tried both single and double quotes, which haven't resolved the issues I'm getting. Not sure what else to try. This is what I've tried:

REMOTE_DIRECTORY="SRC Test Data"
export workdir=/home/ubuntu/tmp

lftp -u $USER,$PASS $HOST <<EOF
set ftp:ssl-protect-data true
set ftp:ssl-force true
set ssl:verify-certificate no
pwd 
cd $REMOTE_DIRECTORY
pwd
cd 'SRC Test Data'
pwd
ls -d > $workdir/src_list
quit
EOF

The output of that script is:

ftp://FTP_User-RW:chars@sslftp.domain
Usage: cd remote-dir
ftp://FTP_User-RW:chars@sslftp.domain
ftp://FTP_User-RW:chars@sslftp.domain/SRC%20Test%20Data

So it clearly is working only when I explictly enter in the folder name in the cd command. How do I do it though with the variable?

1 Answers1

0

When the variable expands, it is like typing

cd SRC Test Data

and the spaces are causing it to blow up.

Try:

 cd "$REMOTE_DIRECTORY"

Also see Why does my shell script choke on whitespace or other special characters?

Wildcard
  • 36,499
whysyn
  • 11
  • 1
    Don't know why this was downvoted; it's a perfectly correct answer even if the terminology isn't perfect. If anyone wants to read further, look into "parameter expansion" and "word splitting" (and just read the linked question). – Wildcard Aug 23 '17 at 21:22