curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: Curl for downloading a file from SFTP server with wildcard

From: Aleksandar Lazic <al-curlusers_at_none.at>
Date: Sat, 09 Feb 2019 14:50:18 +0100

Hi.

Am 08-02-2019 11:28, schrieb Yogesh Gite:

> Hi Everyone,
>
> I am trying to download the txt file from a SFTP server. My curl
> includes a wildcard as the file name on server is constantly changing
> having some fixed characters. I get curl 79 or 78 error.Dont know
> what's wrong. Any help would be appreciated !
>
> Curl :
>
> Curl -u UN:PW sftp://hostname/icaps/859011_20181011*_859011.txt
> --insecure -o myfile.txt

curl does not make a remote 'ls 859011_20181011*_859011.txt' therefore
curl try to find the
file '859011_20181011*_859011.txt' which does not exist.

You can try to download the files in two steps.

# 1.) get filenames
FILES=$(curl -sSk -u UN:PW sftp://hostname/icaps/ | awk
'/859011_20181011.*_859011.txt/ {print $9}' )

# 2.) Download files
for i in ${FILES}; do
   curl -sSk -u UN:PW -o local_${i} sftp://hostname/icaps/${i}
done

There are a lot other possible ways to this steps above ;-)

I hope you get the idea.

Regards
Aleks

> Error :
>
> curl: (78) Could not open remote file for reading: No such file or
> directory
>
> curl: (79) Error in the SSH layer.
>
> Thanks!
> -----------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
> Etiquette: https://curl.haxx.se/mail/etiquette.html
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-02-09