0

This question already has an answer here:

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?

marked as duplicate by Wildcard, Rui F Ribeiro, Anthon, Hauke Laging, Stephen Rauch Aug 23 '17 at 22:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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?

  • 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

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