RandomUser22
RandomUser22

Reputation: 9

Bash - ncftpls is not working

So, I'm trying to get the list of files and folders in the uppermost directory of my server and set it as a variable.
I'm using ncftpls to get the list of files and folders. It runs, but it doesn't display any files or folders.

LIST=$(ncftpls -u $USER -p $PASSWORD -P $PORT ftp://$HOST/)
echo $LIST

I tried not setting it as a variable and just running the command ncftpls, but it still won't display any of the files or folders.
The strange this is, though, when I run this script

ncftp -u $USER -p $PASSWORD -P $PORT ftp://$HOST/ <<EOF
ls
EOF

it outputs all the files and folders just fine. Although, then I can't set it as a variable (I don't think).

If anyone has any ideas on what is going on, that'd be much appreciated!

Upvotes: 0

Views: 1024

Answers (1)

that other guy
that other guy

Reputation: 123640

  1. The only acceptable time to use FTP was the 1970s, when you could trust a host by the fact that it was allowed onto the internet.

    Do not try to use it today. Use sftp, rsync, ssh or another suitable alternative.

  2. You can capture output of any command with $(..):

In your case,

list=$(
ncftp -u $USER -p $PASSWORD -P $PORT ftp://$HOST/ <<EOF
ls
EOF
)

This happens to be equivalent to

list=$(ncftp -u $USER -p $PASSWORD -P $PORT ftp://$HOST/ <<< "ls")

Upvotes: 1

Related Questions