Use the ossutil cp command to upload local files to OSS. This command also supports uploading large files.
Precautions
To upload files, you must have the
oss:PutObject,oss:ListParts, andoss:AbortMultipartUploadpermissions. For more information, see Add a custom policy to a RAM user.Batch uploads are supported only when the source is a directory.
When you use the
-u, --updateoption, the system initiates at least one HEAD request for each file to perform a comparison, regardless of whether the destination file exists. If data changes infrequently, this can generate many inefficient requests, degrading performance and increasing costs. Evaluate your business requirements carefully before using this option to avoid unnecessary resource consumption.
Command syntax
ossutil cp source dest [flags]Parameter | Type | Description |
source | string | The local file path. You can use a relative path, an absolute path, or |
dest | string | The destination object path, in the format |
--acl | string | The access control list (ACL) of the object. Valid values:
|
--bandwidth-limit | SizeSuffix | The data transfer rate limit. The minimum value is 1024 B/s. The unit is B/s by default. You can specify a unit for the bandwidth value, such as B (byte), K (kilobyte), M (megabyte), or G (gigabyte). For example, 50M specifies a bandwidth limit of 50 MB/s. |
--bigfile-threshold | SizeSuffix | The file size threshold to trigger a multipart upload, download, or copy. The default value is 104857600 bytes (100 MiB). |
--cache-control | string | Specifies how clients, such as browsers, should cache the object. |
--content-disposition | string | Specifies whether the object is displayed inline or downloaded as an attachment. |
--content-encoding | string | Specifies the content encoding of the object. |
--content-type | string | The content type of the object. |
--copy-props | string | Specifies which properties to copy from the source object. Valid values:
|
--checkpoint-dir | string |
|
-d, --dirs | string | When copying a directory, this option copies only the files at the top level of the source directory and ignores its subdirectories. |
--encoding-type | string | The encoding type of the input object name or file name. The only valid value is |
--end-with | string | Includes only files whose names end with the specified string. |
--exclude | stringArray | The exclusion rules for paths or file names. |
--exclude-from | stringArray | Reads exclusion rules from a rule file. |
--expires | stringArray | Specifies the absolute expiration time for the cached content. |
--files-from | stringArray | Reads a list of source file names from a file, ignoring empty lines or commented lines. This option is for filtering purposes only. |
--files-from-raw | stringArray | Reads a list of source file names from a file. This option is for filtering purposes only. |
--filter | stringArray | The filtering rules for 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 inclusion rules for paths or file names. Note For more information about filtering options, see Filter options. |
--include-from | stringArray | Reads inclusion rules from a rule file. |
-j, --job | int | The number of concurrent upload tasks. Default value: 3. Note This option is effective only when used with |
--listObjects | / | Uses the ListObjects API operation to list objects. |
--max-size | SizeSuffix | The maximum size of a file to transfer. The value is in bytes by default, but you can use a 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 key=value format. |
--metadata-directive | string | Specifies how to set the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The exclusion rules for object metadata. |
--metadata-filter | stringArray | The filtering rules for object metadata. |
--metadata-filter-from | stringArray | Reads object metadata filtering rules from a rule file. |
--metadata-include | stringArray | The inclusion rules for object metadata. |
--min-age | Duration | Uploads only files modified at least the specified time interval ago. The default unit is seconds. You can use a unit suffix, such as 1h for 1 hour. Note
|
--max-age | Duration | Uploads only files modified within the specified time interval. The default unit is seconds. You can use a unit suffix, such as 1h for 1 hour. Note
|
--min-mtime | Time | Uploads only files modified after the specified time. The time must be in UTC format. Example: 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Uploads only files modified before the specified time. The time must be in UTC format. Example: 2006-01-02T15:04:05. |
--min-size | SizeSuffix | The minimum size of a file to transfer. The value is in bytes by default, but you can use a suffix, such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--no-progress | / | Disables the progress bar. |
--page-size | int | The maximum number of objects to list in each paged request during a batch upload. The value must be in the range of 1 to 1,000. Default value: 1000. |
--parallel | int | For a single large file, this sets the number of parts to upload concurrently. |
--part-size | SizeSuffix | The size of each part in a multipart upload. By default, ossutil calculates an optimal part size based on the file size. The value must be in the range of 100 KiB to 5 GiB. |
-r, --recursive | / | When uploading a directory, you must specify this option to recursively upload all of its files and subdirectories. |
--request-payer | string | Specifies who pays for the request. Set this to |
--size-only | / | Uploads only source files that have a different size than the destination files. |
--storage-class | string | The storage class of the object. Valid values:
|
--tagging | strings | Specifies tags for the object in key=value format. You can specify this option multiple times to add multiple tags. |
--tagging-directive | string | Specifies how to set the tags of the destination object. Valid values:
|
-u, --update | / | Uploads a file only if the source file is newer than the destination file or if the destination file does not exist. Note If a destination file has the same last-modified time as the source file, it is re-uploaded. |
--ignore-existing | / | Skips destination files that already exist. |
For more information, see Command-line options.
The destination object is named based on the following rules:
If you upload a single file and the prefix is empty, the object name is the same as the source file name.
If you upload a single file and the prefix ends with a forward slash (/), the object name is
prefix+ source file name.If you upload multiple files and the prefix is empty, the object name is the relative path of the source file.
If you upload multiple files and the prefix ends with a forward slash (/), the object name is
prefix+ relative path of the source file.If you upload multiple files and the prefix does not end with a forward slash (/), the object name is
prefix+ / + relative path of the source file.
The relative path is the portion of a file's path that follows the source directory specified in the command. For example, in the command ossutil cp -r /root/dir/ oss://..., the relative path for /root/dir/subdir/test.txt is subdir/test.txt.
Examples
Upload a single file
Upload a single file
Upload the local file
examplefile.txtto thedesfolder/directory in theexamplebucketbucket.ossutil cp D:/localpath/examplefile.txt oss://examplebucket/desfolder/
Upload multiple files
Upload all files in a directory
Recursively upload all files from the local directory
localfolder/to thedesfolder/directory in theexamplebucketbucket.ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/Batch upload files that match specific criteria
Recursively upload only the files with the .txt extension.
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ --include "*.txt"Batch upload using 10 concurrent tasks
ossutil cp -r D:/localpath/localfolder/ oss://examplebucket/desfolder/ -f -j 10
Limit upload speed
Uploads the local file
upload.rarto thedesfolder/directory in theexamplebucketbucket and limits the upload speed to 20 MB/s. The bandwidth limit is specified in bytes per second (B/s).ossutil cp D:/upload.rar oss://examplebucket/desfolder/ --bandwidth-limit 20971520Uploads the local file
file.rarto thedesfolder/directory in theexamplebucketbucket and limits the upload speed to 50 MB/s. The unit for the bandwidth limit is specified as MB/s.ossutil cp D:/file.rar oss://examplebucket/desfolder/ --bandwidth-limit 50M