summaryrefslogtreecommitdiff
path: root/nquire
blob: 4754f1c6e9b4dbb71a58e5d3ecd9c6c39b22133d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
#!/bin/sh

# ===========================================================================
#
#                            PUBLIC DOMAIN NOTICE
#            National Center for Biotechnology Information (NCBI)
#
#  This software/database is a "United States Government Work" under the
#  terms of the United States Copyright Act.  It was written as part of
#  the author's official duties as a United States Government employee and
#  thus cannot be copyrighted.  This software/database is freely available
#  to the public for use. The National Library of Medicine and the U.S.
#  Government do not place any restriction on its use or reproduction.
#  We would, however, appreciate having the NCBI and the author cited in
#  any work or product based on this material.
#
#  Although all reasonable efforts have been taken to ensure the accuracy
#  and reliability of the software and data, the NLM and the U.S.
#  Government do not and cannot warrant the performance or results that
#  may be obtained by using this software or data. The NLM and the U.S.
#  Government disclaim all warranties, express or implied, including
#  warranties of performance, merchantability or fitness for any particular
#  purpose.
#
# ===========================================================================
#
# File Name:  nquire
#
# Author:  Jonathan Kans, Aaron Ucko
#
# Version Creation Date:   03/28/20
#
# ==========================================================================

for x in "$@"
do
  if [ "x$x" = "x-newmode" ]
  then
    USE_NEW_EDIRECT=1
    break
  fi
done

# pth must contain cacert.pem certificate (previously within aux/lib/perl5/Mozilla/CA/ subdirectory)

pth=$( dirname "$0" )

PERL=""

# set PERL path if using old EDirect

case "${USE_NEW_EDIRECT}" in
  "" | [FfNn]* | 0 | [Oo][Ff][Ff] )
    PERL=perl
    case "$( uname -s )" in
      CYGWIN_NT*)
        # Use a negative match here because the shell treats 0 as success.
        if perl -e 'exit $^O !~ /^MSWin/'; then
           pth=$( cygpath -w "$pth" )
        fi
        ;;
      Darwin )
        PERL="/usr/bin/perl"
        ;;
    esac
    ;;
  * )
    ;;
esac

# conditionally execute original Perl implementation

if [ -n "${PERL}" ]
then
  exec "${PERL}" "$pth"/edirect.pl -nquir "$@"
  exit 0
fi

# help and example texts

PrintHelp() {

  version=$( einfo -newmode -version )
  echo "nquire $version"
  cat << "EOF"

Query Commands

  -url    Sends query with HTTP POST
  -get    Uses HTTP GET instead of POST

  -lst    Lists contents of FTP site
  -ftp    Retrieves data from FTP site

File Downloads

  -dwn    Downloads FTP data to file
  -asp    Uses Aspera download, if configured

Examples

  nquire -url https://eutils.ncbi.nlm.nih.gov entrez/eutils einfo.fcgi |
  xtract -pattern DbList -sep "\n" -element DbName | sort -f

  nquire -url https://eutils.ncbi.nlm.nih.gov entrez/eutils elink.fcgi \
    -dbfrom pubmed -db pubmed -cmd neighbor -linkname pubmed_pubmed -id 2539356

  nquire -get https://icite.od.nih.gov/api/pubs -pmids 1937004 10838572 |
  xtract -j2x |
  xtract -pattern opt -element cited_by references |
  accn-at-a-time

  nquire -get "http://collections.mnh.si.edu/services/resolver/resolver.php" \
    -voucher "Birds:625456" |
  xtract -pattern Result -element ScientificName Country

  nquire -get http://w1.weather.gov/xml/current_obs/KSFO.xml |
  xtract -pattern current_observation -tab "\n" \
    -element weather temp_f wind_dir wind_mph

  nquire -get https://api.bigdatacloud.net/data/reverse-geocode-client \
    -latitude 41.7909 -longitude "\-87.5994" |
  xtract -j2x |
  xtract -pattern opt -element countryCode \
    -block administrative -if description -starts-with "state " -element name \
    -block administrative -if description -starts-with "city " -element name |
  tr '\t' '\n'

  nquire -ftp ftp.ncbi.nlm.nih.gov pub/gdp ideogram_9606_GCF_000001305.14_850_V1 |
  grep acen | cut -f 1,2,6,7 | awk '/^X\t/'

  nquire -lst ftp://nlmpubs.nlm.nih.gov online/mesh/MESH_FILES/xmlmesh

  nquire -dwn ftp.nlm.nih.gov online/mesh/MESH_FILES/xmlmesh desc2020.zip

  for sect in baseline updatefiles
  do
    nquire -lst ftp.ncbi.nlm.nih.gov pubmed "$sect" |
    grep -v ".md5" | grep "xml.gz" |
    skip-if-file-exists | tee /dev/tty |
    nquire -asp ftp.ncbi.nlm.nih.gov pubmed "$sect"
  done

EOF
}

PrintExamples() {

  version=$( einfo -newmode -version )
  echo "nquire $version"
  cat << "EOF"

Medical Subject Headings

  nquire -get "http://id.nlm.nih.gov/mesh/sparql" \
    -query "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
      SELECT DISTINCT ?class FROM <http://id.nlm.nih.gov/mesh> \
      WHERE { ?s rdf:type ?class } ORDER BY ?class" |
  xtract -pattern result -pfx "meshv:" -first "uri[http://id.nlm.nih.gov/mesh/vocab#|]"

MeSH Predicates

  nquire -get "http://id.nlm.nih.gov/mesh/sparql" \
    -query "SELECT DISTINCT ?p FROM <http://id.nlm.nih.gov/mesh> \
      WHERE { ?s ?p ?o } ORDER BY ?p" |
  xtract -pattern result -pfx "meshv:" -first "uri[http://id.nlm.nih.gov/mesh/vocab#|]"

WikiData Predicate List

  nquire -url "https://query.wikidata.org/sparql" \
    -query "SELECT ?property ?propertyType ?propertyLabel \
      ?propertyDescription ?propertyAltLabel WHERE { \
      ?property wikibase:propertyType ?propertyType . SERVICE wikibase:label \
      { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en'. } } \
      ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))" |
  xtract -pattern result -first "uri[http://www.wikidata.org/entity/|]" -first literal

Vitamin Binding Site

  nquire -get "http://www.wikidata.org/entity/Q22679758" |
  xtract -j2x |
  xtract -pattern entities -group claims -block P527 -element "value/id"

Children of JS Bach

  nquire -url "https://query.wikidata.org/sparql" \
    -query "SELECT ?child ?childLabel WHERE \
      { ?child wdt:P22 wd:Q1339. SERVICE wikibase:label \
        { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en'. } }" |
  xtract -pattern result -block binding -if "@name" -equals childLabel -element literal

Eye Color Frequency

  nquire -url "https://query.wikidata.org/sparql" \
    -query "SELECT ?eyeColorLabel WHERE \
      { ?human wdt:P31 wd:Q5. ?human wdt:P1340 ?eyeColor. SERVICE wikibase:label \
        { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en'. } }" |
  xtract -pattern result -element literal |
  sort-uniq-count-rank

EOF
}

# if present, -newmode must be first argument

if [ $# -gt 0 ]
then
  case "$1" in
    -newmode )
      shift
      ;;
  esac
fi

# check for help commands

if [ $# -gt 0 ]
then
  case "$1" in
    -version )
      version=$( einfo -newmode -version )
      echo "$version"
      exit 0
      ;;
    -h | -help | --help )
      PrintHelp
      exit 0
      ;;
    -examples )
      PrintExamples
      exit 0
      ;;
  esac
fi

# allow environment variable to set preference for curl or wget (undocumented)

helper=""

if [ -n "${NQUIRE_HELPER}" ]
then
  helper="${NQUIRE_HELPER}"
fi

# allow environment variable to set curl connection timeout (undocumented)

timeout=20

if [ -n "${NQUIRE_TIMEOUT}" ]
then
  timeout="${NQUIRE_TIMEOUT}"
fi

# check for leading flags

debug=false
log=false

while [ $# -gt 0 ]
do
  case "$1" in
    -debug )
      debug=true
      shift
      ;;
    -log )
      log=true
      shift
      ;;
    -curl )
      # override setting from environment variable (undocumented)
      helper="curl"
      shift
      ;;
    -wget )
      # override setting from environment variable (undocumented)
      helper="wget"
      shift
      ;;
    * )
      # allows while loop to check for multiple flags
      break
      ;;
  esac
done

# check for presence of curl or wget

case "$helper" in
  curl | CURL | CUrl | Curl | cUrl | cURL )
    binary=$( command -v curl )
    if [ ! -x "$binary" ]
    then
      echo "ERROR: required curl helper is not present" >&2
      exit 1
    fi
    ;;
  wget | WGET | WGet | Wget | wGet | wGET )
    binary=$( command -v wget )
    if [ ! -x "$binary" ]
    then
      echo "ERROR: required wget helper is not present" >&2
      exit 1
    fi
    ;;
  * )
    binary=$( command -v curl )
    if [ ! -x "$binary" ]
    then
      binary=$( command -v wget )
    fi
    if [ ! -x "$binary" ]
    then
      echo "ERROR: nquire requires either curl or wget" >&2
      exit 1
    fi
    ;;
esac

# subset of perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'

Escape() {

  echo "$1" |
  sed -e "s/%/%25/g" \
      -e "s/!/%21/g" \
      -e "s/#/%23/g" \
      -e "s/&/%26/g" \
      -e "s/'/%27/g" \
      -e "s/*/%2A/g" \
      -e "s/+/%2B/g" \
      -e "s/,/%2C/g" \
      -e "s|/|%2F|g" \
      -e "s/:/%3A/g" \
      -e "s/;/%3B/g" \
      -e "s/=/%3D/g" \
      -e "s/?/%3F/g" \
      -e "s/@/%40/g" \
      -e "s/|/%7C/g" \
      -e "s/ /%20/g" |
  sed -e 's/\$/%24/g' \
      -e 's/(/%28/g' \
      -e 's/)/%29/g' \
      -e 's/</%3C/g' \
      -e 's/>/%3E/g' \
      -e 's/\[/%5B/g' \
      -e 's/\]/%5D/g' \
      -e 's/\^/%5E/g' \
      -e 's/{/%7B/g' \
      -e 's/}/%7D/g'
}

# initialize variables

mode=""

url=""
sls=""

arg=""
amp=""
cmd=""
pfx=""

# optionally include nextra.sh script, if present, for internal NCBI maintenance functions (undocumented)

if [ -f "$pth"/nextra.sh ]
then
  # dot command is equivalent of "source"
  . "$pth"/nextra.sh
fi

# get extraction method

if [ $# -gt 0 ]
then
  case "$1" in
    -url | -get | -lst | -ftp | -dwn | -asp )
      mode="$1"
      shift
      ;;
    -* )
      exec >&2
      echo "$0: Unrecognized option $1" >&2
      exit 1
      ;;
    * )
      echo "$0: Missing command $1" >&2
      exit 1
      ;;
  esac
fi

# collect URL directory components

while [ $# -gt 0 ]
do
  case "$1" in
    -ncbi )
      # shortcut for NCBI base (undocumented)
      shift
      url="https://www.ncbi.nlm.nih.gov"
      sls="/"
      ;;
    -eutils )
      # shortcut for EUtils base (undocumented)
      shift
      url="https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
      sls="/"
      ;;
    -pubchem )
      # shortcut for PubChem REST base (undocumented)
      shift
      url="https://pubchem.ncbi.nlm.nih.gov/rest/pug"
      sls="/"
      ;;
    -* )
      # otherwise leading dash indicates end of path, switch to arguments
      break
      ;;
    * )
      dir="$1"
      # remove trailing slash directory delimiter
      dir=${dir%/}
      shift
      url="$url$sls$dir"
      sls="/"
      ;;
  esac
done

# collect argument tags paired with (escaped) values

while [ $# -gt 0 ]
do
  case "$1" in
    -* )
      cmd="$1"
      # remove leading dash from argument
      cmd=${cmd#-}
      # add argument and command
      arg="$arg$amp$cmd"
      # subsequent commands preceded by ampersand
      amp="&"
      # precede first value (if any) with equal sign
      pfx="="
      shift
      ;;
    * )
      val="$1"
      # remove initial backslash used to protect leading minus sign
      val=${val#\\}
      # URL encoding
      val=$( Escape "$val" )
      arg="$arg$pfx$val"
      # concatenate run of values with commas
      pfx=","
      shift
      ;;
  esac
done

# debugging output to stderr

if [ "$debug" = true ]
then
  if [ -z "$arg" ]
  then
    echo "PTH $pth" >&2
    echo "URL $url" >&2
  elif [ "$mode" = "-url" ]
  then
    echo "curl -fsSL \"$url\" -d \"$arg\"" >&2
  elif [ "$mode" = "-get" ]
  then
    echo "curl -fsSL \"$url?$arg\"" >&2
  else
    echo "PTH $pth" >&2
    echo "URL $url" >&2
    echo "ARG $arg" >&2
  fi
  exit 0
fi

# pause if Entrez Utilities server to avoid exceeding request frequency limit

slow=false

case "${SLOW_EDIRECT}" in
  "" | [FfNn]* | 0 | [Oo][Ff][Ff] )
    ;;
  * )
    slow=true
    ;;
esac

hasperl=$( command -v perl )

case $url in
  *"dev.ncbi.nlm.nih.gov/entrez/eutils/"* | *"internal.ncbi.nlm.nih.gov/entrez/eutils/"* )
    if [ "$slow" = true ]
    then
      sleep 1
    elif [ -x "$hasperl" ]
    then
      perl -MTime::HiRes -e 'Time::HiRes::usleep(1000)'
    fi
    ;;
  *"/entrez/eutils/"* )
    if [ "$slow" = true ]
    then
      sleep 1
    elif [ -x "$hasperl" ]
    then
      case $arg in
        *"api_key="* )
          perl -MTime::HiRes -e 'Time::HiRes::usleep(110000)'
          ;;
        * )
          perl -MTime::HiRes -e 'Time::HiRes::usleep(350000)'
          ;;
      esac
    else
      sleep 1
    fi
    ;;
esac

# set up colors for error report

ColorSetup() {

  if [ -z "$TERM" ] || [ ! -t 2 ]
  then
    red_fg=""
    blue_fg=""
    orig_colors=""
  elif command -v tput >/dev/null
  then
    red_fg="$(tput setaf 1)"
    blue_fg="$(tput setaf 4)"
    orig_colors="$(tput op)"
  else
    # assume ANSI
    escape="$(printf '\033')"
    red_fg="$escape[31m"
    blue_fg="$escape[34m"
    orig_colors="$escape[39;49m"
  fi
}

# common function to execute curl or wget command

SendRequest() {

  ColorSetup
  when=$( date )

  case "$binary" in
    */curl )
      if [ "$log" = true ]
      then
        echo "${blue_fg}$@${orig_colors}" >&2
      fi

      temp=$(mktemp /tmp/NQUIRE_HEADER.XXXXXXXXX)

      if [ -f "$pth"/cacert.pem ]
      then
        curl --http1.0 --connect-timeout 20 -fsSL --capath "$pth"/cacert.pem -D "$temp" "$@" 2>&1
      else
        curl --http1.0 --connect-timeout 20 -fsSL -D "$temp" "$@" 2>&1
      fi

      # capture and check curl return value
      res=$?
      if [ "$res" -ne 0 ]
      then
        # report failure
        echo "${red_fg}ERROR: curl command failed ( $when ) with: $res${orig_colors}" >&2
        echo "${blue_fg}$@${orig_colors}" >&2
        # show return code in first line of header
        cat "$temp" | head -n 1 >&2
      fi

      rm "$temp"
      ;;
    */wget )
      if [ "$log" = true ]
      then
        echo "${blue_fg}$@${orig_colors}" >&2
      fi

      temp=$(mktemp /tmp/NQUIRE_HEADER.XXXXXXXXX)

      full_output=""
      if [ -f "$pth"/cacert.pem ]
      then
        wget -qS -O - --ca-certificate="$pth"/cacert.pem "$@" 2> "$temp"
      else
        wget -qS -O - --no-check-certificate "$@" 2> "$temp"
      fi

      # capture and check wget return value
      res=$?
      if [ "$res" -ne 0 ]
      then
        # report failure
        echo "${red_fg}ERROR: wget command failed ( $when ) with: $res${orig_colors}" >&2
        echo "${blue_fg}$@${orig_colors}" >&2
        # show return code in first line of header
        cat "$temp" | head -n 1 >&2
      fi

      rm "$temp"
      ;;
  esac
}

# can use Aspera if installed

APPPATH=""
KEYPATH=""
KEYNAME=asperaweb_id_dsa.openssh

HasAspera() {

  case "$( uname -s )" in
    Darwin )
      sysdir='/Applications/Aspera Connect.app/Contents/Resources'
      sysdir2=/bin
      userdir=$HOME$sysdir
      ;;
    CYGWIN_NT* )
      sysdir='/cygdrive/c/Program Files/Aspera/Aspera Connect/bin'
      sysdir2='/cygdrive/c/Program Files (x86)/Aspera/Aspera Connect/bin'
      userdir="$( cygpath -H )/$USER/AppData/Local/Programs/Aspera/Aspera Connect/bin"
      ;;
    * )
      sysdir=/opt/aspera/bin
      sysdir2=/bin
      userdir=$HOME/.aspera/connect/bin
      ;;
  esac
  for d in "$sysdir" "$sysdir2" "$userdir"
  do
    if "$d/ascp" --version 2>&1 | grep '^Aspera' >/dev/null
    then
      APPPATH=$d
      break
    fi
  done
  if [ -z "$APPPATH" ]  &&  ascp --version 2>&1 | grep '^Aspera' >/dev/null
  then
    APPPATH=$( type -path ascp )
    APPPATH=$( dirname "$APPPATH" )
  fi
  if [ -z "$APPPATH" ]
  then
    return 1
  fi

  for d in "$APPPATH" "$sysdir" "$sysdir2" "$userdir"
  do
    if [ -f "$d/../etc/$KEYNAME" ]
    then
      KEYPATH=$d/../etc
      break
    elif [ -f "$d/$KEYNAME" ]
    then
      KEYPATH=$d
      break
    fi
  done
  if [ -z "$KEYPATH" ]
  then
    return 1
  fi

  return 0
}

if [ "$mode" = "-asp" ]
then
  HasAspera
  if [ "$?" = 1 ]
  then
    # Aspera not found, revert to download with FTP
    mode="-dwn"
  else
    # add colon before first slash in URL for Aspera
    url=$(echo "$url" | sed -e 's|/|:/|')
  fi
fi

# common method for file download

failed=""

DownloadOneFile() {

  urlfl="$1"
  fl="$2"

  if [ ! -f "$fl" ]
  then
    # only download if local file does not already exist
    case "$mode" in
      -dwn )
        SendRequest "$urlfl" > "$fl"
        ;;
      -asp )
        "$APPPATH/ascp" -T -q -k 1 -l 500m -i "$KEYPATH/$KEYNAME" \
        "anonftp@$urlfl" "."
        ;;
    esac
    if [ ! -f "$fl" ]
    then
      # report failure to download requested file
      failed="$failed\n$fl"
    fi
  fi
}

# send request with method-specific arguments

case "$mode" in
  -url )
    case "$binary" in
      */curl )
        if [ -n "$arg" ]
        then
          SendRequest "$url" -d "$arg"
        else
          SendRequest "$url"
        fi
        ;;
      */wget )
        if [ -n "$arg" ]
        then
          SendRequest --post-data="$arg" "$url"
        else
          SendRequest --post-data="" "$url"
        fi
        ;;
    esac
    ;;
  -get )
    if [ -n "$arg" ]
    then
      SendRequest "$url?$arg"
    else
      SendRequest "$url"
    fi
    ;;
  -lst )
    case "$binary" in
      */curl )
        SendRequest "$url/" |
        tr -s ' ' | tr ' ' '\t' | cut -f 9 | grep '.'
        ;;
      */wget )
        SendRequest "$url" |
        sed -e 's/<[^>]*>//g' | tr ' ' '\t' | cut -f 1 | grep '.'
        ;;
    esac
    ;;
  -ftp )
    if [ -t 0 ]
    then
      SendRequest "$url"
    else
      # read file names from stdin, URL contains base address of server
      while IFS=$'\t' read fl
      do
        SendRequest "$url/$fl"
      done
    fi
    ;;
  -dwn | -asp )
    if [ -t 0 ]
    then
      # file name is included in URL constructed from command line arguments
      fl=$( basename "$url" )
      DownloadOneFile "$url" "$fl"
    else
      # read file names from stdin, URL contains base address of server
      while IFS=$'\t' read fl
      do
        DownloadOneFile "$url/$fl" "$fl"
      done
    fi
    if [ -n "$failed" ]
    then
      echo -e "\nFAILED TO DOWNLOAD:\n$failed\n" >&2
      exit 1
    fi
    ;;
  * )
    echo "$0: Unrecognized option $1" >&2
    exit 1
    ;;
esac