curl-users
Re: Wildcards in ftp file uploads
Date: Wed, 12 Jun 2013 21:46:40 +0200
On Wed, Jun 12, 2013 at 12:22:30PM -0400, Michael Peterson wrote:
> I tried placing the file name in quotes per this suggestion, and
> nothing was uploaded. Single, precise file names work fine inside
> double or single quotes. Nothing with a wildcard in it seems to work
> though, including previous examples that would upload single files.
It should become more clear if you think about how the parameters are
expanded. The shell expands some, and curl expands others.
> > curl(1) is non-direct about its use of quoting for the -T option, but
> > it's very clear that you can specify the -T option multiple times if you
> > instead want to expand the globs yourself. You could do something like
> > (in bash):
> >
> > uploads=()
> > for f in *.txt; do
> > [[ -e $f ]] && uploads+=(-T "$f")
> > done
> >
> > if (( ${#uploads[*]} )); then
> > curl -v ftp://1.1.1.1 -u user:Pass "${uploads[@]}" ftp://1.1.1.1
> > fi
Except that curl requires one URL per -T option.
In the case where there's at least one file and none of the file names
contain spaces, the following one-liner would work:
curl -v -u user:Pass $(echo *.txt | sed 's@^\| @ ftp://1.1.1.1 -T @g')
Another approach is to use curl's upload globbing feature. This
uses a single -T parameter with file names in curly brackets. This approach
is followed by this command:
curl -v -u user:Pass $(echo *.txt | sed -e 's/ /,/g' -e 's/^/{/' -e 's/$/}/')
> I'm going to try working with this and I'll let everyone know how it
> turns out. I'm not the best at scripting so it may take a while.
>
> In the mean time, if anyone has any other insights into using wild
> cards let me know. I'd still like to know if this was intended
> implemented behavior or not.
Read the man page for the -T option and it explains these possibilities.
>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-12