Discussion:
lftp and patterns
T***@bertelsmann.de
2014-04-15 13:27:12 UTC
Permalink
Hi,
is it somehow possible, to list files by using a pattern like:
ls *.csv
dir *.csv

And if no files are found, exit that ls or dir command with an exit code <> 0?

Regards,
Tilo
Alexander Lukyanov
2014-06-06 15:59:30 UTC
Permalink
Which backend protocol do you use? If ftp, then ls arguments are wholly
passed to server side as LIST argument. If other protocols, then most
probably you may only specify a directory to list.

There is another command - cls - which handles arguments locally and
provides better functionality compared with plain "ls". Try it. Exit code
may be not that you want though.
Post by T***@bertelsmann.de
Hi,
ls *.csv
dir *.csv
And if no files are found, exit that ls or dir command with an exit code <> 0?
Regards,
Tilo
_______________________________________________
lftp mailing list
http://univ.uniyar.ac.ru/mailman/listinfo/lftp
--
Alexander.
T***@bertelsmann.de
2014-06-10 08:43:23 UTC
Permalink
Sorry I’ve forgot to mention, that we’re mostly using SFTP and FTPS (FTP only in rare cases).

From: MÃŒtze, Tilo, NMD-C4.2
Sent: Tuesday, June 10, 2014 10:41 AM
To: 'Alexander Lukyanov'
Cc: Lista LFTp
Subject: RE: [lftp] lftp and patterns

Hi Alexander,
yep, we’ve already tried cls before. But regarding the exit code, it works the same as ls.

Exit code are an indicator if something went wrong and with lftp you have a strong partner as you can use “||” and “&&” to combine commands and exit with a specific return code, e.g. if there is no data. So to us it makes much sense, to have a possibility in lftp to check for patterns and end ls command with an error code, if no files are found.

Thanks and regards,
Tilo

From: Alexander Lukyanov [mailto:***@gmail.com]
Sent: Friday, June 06, 2014 6:00 PM
To: MÃŒtze, Tilo, NMD-C4.2
Cc: Lista LFTp
Subject: Re: [lftp] lftp and patterns

Which backend protocol do you use? If ftp, then ls arguments are wholly passed to server side as LIST argument. If other protocols, then most probably you may only specify a directory to list.

There is another command - cls - which handles arguments locally and provides better functionality compared with plain "ls". Try it. Exit code may be not that you want though.

2014-04-15 17:27 GMT+04:00 <***@bertelsmann.de<mailto:***@bertelsmann.de>>:
Hi,
is it somehow possible, to list files by using a pattern like:
ls *.csv
dir *.csv

And if no files are found, exit that ls or dir command with an exit code <> 0?

Regards,
Tilo


_______________________________________________
lftp mailing list
***@uniyar.ac.ru<mailto:***@uniyar.ac.ru>
http://univ.uniyar.ac.ru/mailman/listinfo/lftp
--
Alexander.
T***@bertelsmann.de
2014-06-10 08:41:04 UTC
Permalink
Hi Alexander,
yep, we’ve already tried cls before. But regarding the exit code, it works the same as ls.

Exit code are an indicator if something went wrong and with lftp you have a strong partner as you can use “||” and “&&” to combine commands and exit with a specific return code, e.g. if there is no data. So to us it makes much sense, to have a possibility in lftp to check for patterns and end ls command with an error code, if no files are found.

Thanks and regards,
Tilo

From: Alexander Lukyanov [mailto:***@gmail.com]
Sent: Friday, June 06, 2014 6:00 PM
To: MÃŒtze, Tilo, NMD-C4.2
Cc: Lista LFTp
Subject: Re: [lftp] lftp and patterns

Which backend protocol do you use? If ftp, then ls arguments are wholly passed to server side as LIST argument. If other protocols, then most probably you may only specify a directory to list.

There is another command - cls - which handles arguments locally and provides better functionality compared with plain "ls". Try it. Exit code may be not that you want though.

2014-04-15 17:27 GMT+04:00 <***@bertelsmann.de<mailto:***@bertelsmann.de>>:
Hi,
is it somehow possible, to list files by using a pattern like:
ls *.csv
dir *.csv

And if no files are found, exit that ls or dir command with an exit code <> 0?

Regards,
Tilo


_______________________________________________
lftp mailing list
***@uniyar.ac.ru<mailto:***@uniyar.ac.ru>
http://univ.uniyar.ac.ru/mailman/listinfo/lftp
--
Alexander.
Alexander V. Lukyanov
2014-06-10 10:58:43 UTC
Permalink
Post by T***@bertelsmann.de
Hi Alexander,
yep, we’ve already tried cls before. But regarding the exit code, it works the same as ls.
You can use temporary files like this:

lftp> cls *.csv > listing
lftp> source -e "test -s listing && echo LFTP-COMMAND"

It's not pretty, but works...

You can also try attached patch, which adds this possibility:

glob .empty *.csv && echo "There are no *.csv files"

Suggestions on the command name are welcome (it's not released yet).
--
Alexander.
Loading...