When you need to download resources such as files, images, and videos that have been uploaded to OSS to your local device, you can use the cp command of ossutil.
Precautions
To download files, you must have the oss:GetObject
or oss:ListObjects
permission. For more information, see Grant custom permissions to a RAM user.
Command syntax
ossutil cp oss://bucket[/prefix] local-path [flags]
Parameter | Type | Description |
local-path | string | Supports relative paths, absolute paths, and |
prefix | string | The prefix in the name of the object that you want to download. If the value of the prefix parameter ends with a forward slash (/), ossutil downloads multiple objects. If the value of the prefix parameter does not end with a forward slash (/), ossutil determines whether to download multiple objects or a single object based on the command line options. |
--acl | string | The access control list (ACL) of the object. Valid values:
|
--bigfile-threshold | int | The object size threshold for multipart upload, download, and copy. Default value: 104857600. |
--cache-control | string | The caching behavior in web browsers when the object is downloaded. |
--checkers | int | The number of checkers that you want to run in parallel. Default value: 16. |
--checkpoint-dir | string | The specified directory for checkpoint information (Default value: |
--content-disposition | string | The display form of the object. |
--content-encoding | string | The encoding method of the object. |
--content-type | string | The content type of the object. |
--copy-props | string | The attributes of the object that you want to download. Valid values:
|
-d, --dirs | string | Matches objects and subdirectories in the current directory, instead of matching objects recursively in subdirectories. |
--encoding-type | string | The encoding method used to encode the object name. Valid value: url. |
--end-with | string | Matches objects whose names are lexicographically before the specified value (inclusive). |
--exclude | stringArray | The exclusion rule for paths or object names. |
--exclude-from | stringArray | Reads the exclusion rule from a file. |
--expires | stringArray | The absolute expiration time of the cached content. |
--files-from | stringArray | Reads a list of source object names from a file, with empty lines and comment lines ignored. |
--files-from-raw | stringArray | Reads a list of source objects from a file. |
--filter | stringArray | The filter rule for paths or object names. |
--filter-from | stringArray | Reads filter rules from a file. |
-f, --force | / | Forces the operation without requiring user confirmation. |
--include | stringArray | The inclusion rule for paths or object names. |
--include-from | stringArray | Reads inclusion rules from a file. |
-j, --job | int | The number of concurrent tasks that can be performed across multiple objects. Default value: 3. |
--list-objects | / | Specifies that the ListObjects operation is called to list objects. |
--max-size | SizeSuffix | The maximum size of an object that can be transferred. By default, the size is in bytes (B). You can suffix the numerical value with a 1024-based unit: B for byte, K for Kibibyte, M for Mebibyte, G for Gibibyte, T for Tebibyte, or P for Pebibyte. |
--metadata | strings | The user metadata of the object in the key=value format. |
--metadata-directive | string | The method used to configure the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The exclusion rule for object metadata. |
--metadata-filter | stringArray | The filter rule for object metadata. |
--metadata-filter-from | stringArray | Reads the metadata filter rule from a file. |
--metadata-include | stringArray | The inclusion rule for object metadata. |
--min-age | Duration | Downloads only files that were modified before the specified time interval. The default unit is seconds. You can use a unit suffix. For example, 1h indicates one hour. Note
|
--max-age | Duration | Downloads only files that were modified within the specified time interval. The default unit is seconds. You can use a unit suffix. For example, 1h indicates one hour. Note
|
--min-mtime | Time | Downloads only files that were modified after the specified time. The time format is UTC. For example, 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Downloads only files that were modified before the specified time. The time format is UTC. For example, 2006-01-02T15:04:05. |
--min-size | SizeSuffix | The minimum size of a file or object that can be transferred. By default, the size is in bytes (B). You can suffix the numerical value with a 1024-based unit: B for byte, K for Kibibyte, M for Mebibyte, G for Gibibyte, T for Tebibyte, or P for Pebibyte. |
--no-progress | / | Does not display the progress bar. |
--page-size | int | The maximum number of objects that can be returned per page. Default value: 1000. Valid values: 1 to 1000. |
--parallel | int | The number of concurrent tasks for internal operations on a single object. |
--part-size | SizeSuffix | The part size. By default, ossutil calculates the appropriate part size based on the object size. The part size ranges from 100 KiB to 5 GiB. |
-r, --recursive | / | If this parameter is specified, the cp command takes effect on all objects that meet the conditions in the bucket. Otherwise, the cp command takes effect only on the objects in the specified path. |
--request-payer | string | The payer of the request. If pay-by-requester is enabled, set this parameter to requester. |
--size-only | / | Specifies that only when the size of the object is different from that of the local file, the object is downloaded. |
--start-after | string | Specifies that objects whose names are alphabetically after the value of the --start-after parameter are returned. |
--storage-class | string | The storage class of the object. Valid values:
|
--tagging | strings | The object tags in key=value pairs. |
--tagging-directive | string | The method used to set tags for the destination object. Valid values:
|
-u, --update | / | Specifies that only when the last modified time of the object is later than that of the local file, the object is downloaded. |
--ignore-existing | / | Ignores existing destination objects. |
For more information, see Command-line options.
The name of a destination object conforms to the following rules:
If a single object is downloaded to a local directory, the downloaded object retains its original name.
If a single object is downloaded with a specified name and no local file with the same name exists, the downloaded object is stored with the specified name.
If multiple objects are downloaded to a specified local directory, the same directory structure in which the objects are stored in OSS is created in the local directory, and the downloaded objects retain their original names.
The relative path of an object that you want to download is the part that follows the specified path in the cp command.
For example, if the path specified in the cp command is /root/dir/, the relative path of the /root/dir/subdir/test.txt file is subdir/test.txt.
Examples
Download a single object
If you do not specify a name for the downloaded object, the name of the source object is used by default. If you specify a name for the downloaded object, the specified name is used in the local device.
Download the object with its original name:
ossutil cp oss://examplebucket/examplefile.txt D:/localpath
Download the object with the specified name:
ossutil cp oss://examplebucket/examplefile.txt D:/localpath/example.txt
Download multiple objects
Download objects of a specific type
If you want to download multiple objects with similar names, such as objects that have the same prefix or suffix, you can use the --include and --exclude options to select objects that meet the conditions.
Download all objects whose file format is not JPG:
ossutil cp oss://examplebucket/destfolder/ D:/localpath/ --exclude "*.jpg" -r
Download a directory
ossutil cp -r oss://examplebucket/destfolder/ D:/localpath/
Download all objects in the root directory of a bucket
ossutil cp -r oss://examplebucket D:/localpath/