Use the ossutil cp command to download resources such as files, images, and videos from OSS to a local machine.
Precautions
To download files, you must have the oss:GetObject and oss:ListObjects permissions. For more information, see Grant custom access policies to Resource Access Management (RAM) users.
Command format
ossutil cp oss://bucket[/prefix] local-path [flags]Parameter | Type | Description |
local-path | string | The local path. Relative paths, absolute paths, and |
prefix | string | The object prefix. If the prefix ends with a forward slash (/), only batch operations are supported. If the prefix does not end with a forward slash (/), ossutil determines whether to perform a single-object download or a batch download based on command-line options. |
--acl | string | The access permissions of the object. Valid values:
|
--bandwidth-limit | SizeSuffix | Limits the network bandwidth to control the data transmission rate. The minimum value is 1024 B/s. The default unit is B/s. When you configure this parameter, you can specify a unit for the bandwidth value as needed. Optional units include B (bytes), K (kilobytes), M (megabytes), and G (gigabytes). For example, 50 M indicates that the bandwidth is limited to 50 MB/s. |
--bigfile-threshold | SizeSuffix | The threshold to enable multipart upload, download, or copy for large files. The default value is 104857600. |
--cache-control | string | Specifies the web page caching behavior when the object is downloaded. |
--checkers | int | The number of checkers that run in parallel. The default value is 16. |
--checkpoint-dir | string | The directory that stores checkpoint information for resumable operations. The default value is |
--content-disposition | string | Specifies how the object is displayed. |
--content-encoding | string | Specifies the encoding format of the object. |
--content-type | string | The content type of the object. |
--copy-props | string | Controls the copy rules for metadata and tags. Valid values:
|
-d, --dirs | string | Downloads the files and subdirectories in the current directory, but does not recursively download all files in all subdirectories. |
--encoding-type | string | The encoding type of the input object name or file name. Valid value: url. |
--end-with | string | Returns objects that are alphabetically before or the same as the specified value. |
--exclude | stringArray | The rules to exclude paths or file names. |
--exclude-from | stringArray | Reads exclusion rules from a rule file. |
--expires | string | Specifies the absolute expiration time of the cached content. |
--files-from | stringArray | Reads the list of source file names from a file. Empty lines or comment lines are ignored. |
--files-from-raw | stringArray | Reads the list of source file names from a file. |
--filter | stringArray | The rules to filter paths or file names. |
--filter-from | stringArray | Reads filtering rules from a rule file. |
-f, --force | / | Forces the operation without a confirmation prompt. |
--include | stringArray | The rules to include paths or file names. |
--include-from | stringArray | Reads inclusion rules from a rule file. |
-j, --job | int | The number of concurrent tasks. The default value is 3. Note This parameter takes effect only when you specify the |
--list-objects | / | Uses the ListObjects operation to list objects. |
--max-size | SizeSuffix | Limits the maximum size of the file to transfer. The default unit is byte. You can also use a unit suffix, such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--metadata | strings | Specifies the user metadata of the object in the key=value format. |
--metadata-directive | string | Specifies how to set the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The rules to exclude object metadata. |
--metadata-filter | stringArray | The rules to filter object metadata. |
--metadata-filter-from | stringArray | Reads object metadata filtering rules from a rule file. |
--metadata-include | stringArray | The rules to include object metadata. |
--min-age | Duration | Downloads only files modified before the specified time interval. The default unit is second. You can use a unit suffix. For example, 1h indicates 1 hour. Note
|
--max-age | Duration | Downloads only files modified within the specified time interval. The default unit is second. You can use a unit suffix. For example, 1h indicates 1 hour. Note
|
--min-mtime | Time | Downloads only files modified after the specified time. The time is in UTC. Example: 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Downloads only files modified before the specified time. The time is in UTC. Example: 2006-01-02T15:04:05. |
--min-size | SizeSuffix | Limits the minimum size of the file to transfer. The default unit is byte. You can also use a unit suffix, such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--no-progress | / | Does not display the progress bar. |
--page-size | int | The maximum number of objects to list per page for a batch download. The default value is 1000. The value ranges from 1 to 1000. |
--parallel | int | The number of concurrent tasks for operations on a single file. |
--part-size | SizeSuffix | The part size. By default, ossutil calculates an appropriate part size based on the file size. The value ranges from 100 KiB to 5 GiB. |
-r, --recursive | / | Performs the operation recursively. If you specify this option, the command is run on all matching objects in the bucket. Otherwise, the command is run only on the object specified by the path. |
--request-payer | string | The payment method for the request. Set this parameter to `requester` if you use the pay-by-requester mode. |
--size-only | / | Downloads only source files whose sizes are different from the destination files. |
--start-after | string | Returns objects that are alphabetically after the specified value. |
--storage-class | string | The storage class of the object. Valid values:
|
--tagging | strings | Specifies the tags of the object in the key=value format. |
--tagging-directive | string | Specifies how to set the tags of the destination object. Valid values:
|
-u, --update | / | Downloads only source files that are newer than the destination files. |
--ignore-existing | / | Skips existing destination files. |
For more information about supported global command-line options, see Global command-line options.
The naming conventions for destination files are as follows:
If you download a single file to a destination directory, a file is created in that directory and named using the relative path of the source file.
If you download a single file and the destination is a file path or a path that does not exist, the downloaded file is saved with the specified name.
For a batch download, subdirectories are created in the destination root directory to match the relative path of the source files. The files are then created in their respective subdirectories.
The relative path of a source file is the object name with the specified source prefix removed. The source prefix includes all characters up to and including the last forward slash (/) in the path.
For example, if you run `cp oss://bucket/root/dir/ ...`, the relative path of the `root/dir/subdir/test.txt` object is `subdir/test.txt`.
Usage examples
Download a single file
If you do not specify a destination file name when you download a file, the file is saved locally with its original name. If you specify a destination file name, the file is saved locally with the specified name.
Save the file with its original name
ossutil cp oss://examplebucket/examplefile.txt D:/localpathSave the file with a specified name
ossutil cp oss://examplebucket/examplefile.txt D:/localpath/example.txt
Download multiple files
Download a specific type of file
To download multiple files that have similar names, such as files with the same prefix or suffix, you can use the --include and --exclude options to filter the files that you want to download.
Download all files except for those in the JPG format:
ossutil cp oss://examplebucket/destfolder/ D:/localpath/ --exclude "*.jpg" -rDownload a folder
ossutil cp -r oss://examplebucket/destfolder/ D:/localpath/Download all files from the root directory of a bucket
ossutil cp -r oss://examplebucket D:/localpath/
Limit the download speed
Download the examplefile.txt file to the current directory and limit the download speed to 20 MB/s.
ossutil cp oss://examplebucket/examplefile.txt . --bandwidth-limit 20971520