"GET" command retrieves multiple files while using wildcard

Hi All

I am using GNU/Linux

This is regarding the get command to retrieve files (filename with wild card characters) from remote server.

I thought Get command can retrieve only 1 file irrespective of the files it has on the remote server And it is the function of mget to retrieve all files using wildcard.

this is the command I am using

 get $remote_path/DOE*.txt $local_path

Here, all the files with DOE*.txt are retrieved.

Is there any way that I can get only the first file with the match and disconnect.

Any suggestion would be appreciated.

Thanks in advance

I don't think GET should retrieve multiple files. Perhaps you meant mget, which is a completely different command.

FTP is very simple and stupid. FTP doesn't have a "get first file and quit" option. You'd have to ls, process the list locally, then re-connect and GET the one specific file you want.

How do you know the first file listed is the one you want, in any case?

It is the GET command and not mget.

Here is the output

cmd: get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE*.txt  /var/ftdata/TEST/DOE/FROM_Laclede
get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE5629407.txt /var/ftdata/TEST/DOE/FROM_Laclede/DOE5629407.txt
- 58 bytes received in 0.00 Seconds 29000.0 Kbytes/sec.
get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE5629421.txt /var/ftdata/TEST/DOE/FROM_Laclede/DOE5629421.txt
- 60 bytes received in 0.00 Seconds 60000.0 Kbytes/sec.
get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE5629432.txt /var/ftdata/TEST/DOE/FROM_Laclede/DOE5629432.txt
- 339 bytes received in 0.00 Seconds 339000.0 Kbytes/sec.
get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE5629444.txt /var/ftdata/TEST/DOE/FROM_Laclede/DOE5629444.txt
- 917 bytes received in 0.00 Seconds 458500.0 Kbytes/sec.
get /ProdData/Fusion/Payables/Invoices/OUT/Source/DOE5629454.txt /var/ftdata/TEST/DOE/FROM_Laclede/DOE5629454.txt
- 137 bytes received in 0.00 Seconds 137000.0 Kbytes/sec.

Are you possibly using sftp as this would allow for "glob(3) characters and may match multiple files"? Then you could ssh to identify the file of interest and sftp (or scp ) exactly this one, then.

1 Like

Sorry! I forgot to mention that . Yes, it is in SFTP session.

Could you please give me the command to ssh the file of interest and then sftp.

Something like

ssh user@host ls /path/to/folder '|' head -n 1 > localfiles

sftp user@host <<EOF
get `cat localfiles`
EOF
1 Like

Thanks Corona688. I am using it in a job scheduling tool and it doesnt allow me to SFTP again.

But have noted it so that I can use it in the future. Thanks for your answers!!

Thanks RudiC

With a recent bash , you could try a "here string"

sftp  user@host  <<< "get $(ssh user@host ls /path/to/folder | head -1)"