curl-curl/docs/cmdline-opts/remote-header-name.md
Daniel Stenberg fa6a46473e
tool_cb_hdr: with -J, use the redirect name as a backup
The -J / --remote-header-name logic now records the file name part used
in the redirects so that it can use the last one as a name if no
Content-Disposition header arrives.

Add tests to verify:

1641: -J with a redirect and extract the CD contents in the second
response

1642: -J with a redirect but no Content-Disposition, use the name from
the Location: header

1643: -J with two redirects, using the last file name and also use
queries and fragments to verify them stripped off

Closes #20430
2026-01-26 12:53:03 +01:00

1.5 KiB

c SPDX-License-Identifier Long Short Protocols Help Category Added Multi See-also Example
Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. curl remote-header-name J HTTP Use the header-provided filename output 7.20.0 boolean
remote-name
-OJ https://example.com/file

--remote-header-name

Tell the --remote-name option to use the server-specified Content-Disposition filename instead of extracting a filename from the URL. If the server-provided filename contains a path, that is stripped off before the filename is used.

The file is saved in the current directory, or in the directory specified with --output-dir.

If the server specifies a filename and a file with that name already exists in the destination directory, it is not overwritten and an error occurs - unless you allow it by using the --clobber option. If the server does not specify a filename then this option has no effect.

There is no attempt to decode %-sequences (yet) in the provided filename, so this option may provide you with rather unexpected filenames.

This feature uses the name from the filename field, it does not yet support the filename* field (filenames with explicit character sets).

Starting in 8.19.0, curl falls back and uses the filename extracted from the last redirect header if no Content-Disposition: header provides a filename.

WARNING: Exercise judicious use of this option, especially on Windows. A rogue server could send you the name of a DLL or other file that could be loaded automatically by Windows or some third party software.