I can list file names actually but a lot of unwanted stuff comes from there also.
> echo "ls *.txt" | sftp user@host:/dir
Connected to 1.1.1.1.
Changing to: /dir
sftp> ls *.txt
1.txt
2.txt
3.txt
Is there a proven/reliable way to list files and only files? I'd like to avoid using head
-like filters if possible.
Best Answer
Use the
-q
option to tellsftp
to be quiet, thereby suppressing most of the output you don't care about:You will still see the lines for the interactive prompt to which you are echoing, e. g.
sftp> ls *.txt
, but those can be filtered out with agrep -v
:As an aside, it's probably better practice to use a batch file, and pass it with the
-b
parameter tosftp
rather thanecho
ing a pipeline into it.If all you really want to do is get a list of files, this might actually be better served with
ssh
than withsftp
(which, after all, is the secure file transfer program):