I am trying to write a script to download a file using curl command line.
According to previous post, I should be able to follow a 301 using the -L
flag. Here is what I am seeing on my Ubuntu 22.04.1 system:
$ curl -s -I "https://dicom.nema.org/medical/dicom/2023c" | head -1
HTTP/1.1 301 Moved Permanently
So let's give it a try:
$ curl -s -L "https://dicom.nema.org/medical/dicom/2023c/source/docbook/part15/part15.xml" | head -5 | tail -1
<title>404 - File or directory not found.</title>
However from my google chrome the link https://dicom.nema.org/medical/dicom/2023c
redirects to https://dicom.nema.org/medical/dicom/current
(hint).
Let's give it a try:
$ curl -s -O "https://dicom.nema.org/medical/dicom/current/source/docbook/part15/part15.xml"
Gives the expected result:
$ head -4 part15.xml | tail -1
<subtitle>DICOM PS3.15 2023c - Security and System Management Profiles</subtitle>
What am I missing here to have a working script to download any version:
$ VERSION=2023c curl "https://dicom.nema.org/medical/dicom/${VERSION}/source/docbook/part15/part15.xml"
For reference:
$ curl --version
curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.13
Release-Date: 2022-01-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets zstd