[Yandex Cloud documentation](../../../index.md) > [Yandex Object Storage](../../index.md) > [Step-by-step guides](../index.md) > Objects > Downloading an object

# Downloading an object


To work with objects in an [encrypted](../../concepts/encryption.md) bucket, a user or [service account](../../../iam/concepts/users/service-accounts.md) must have the following [roles for the encryption key](../../../kms/operations/key-access.md) in addition to the `storage.configurer` [role](../../security/index.md#storage-configurer):

* `kms.keys.encrypter`: To read the key, [encrypt](../../../kms/security/index.md#kms-keys-encrypter) and upload objects.
* `kms.keys.decrypter`: To read the key, [decrypt](../../../kms/security/index.md#kms-keys-decrypter) and download objects.
* `kms.keys.encrypterDecrypter`: This role includes the `kms.keys.encrypter` and `kms.keys.decrypter` [permissions](../../../kms/security/index.md#kms-keys-encrypterDecrypter).

For more information, see [Key Management Service service roles](../../../kms/security/index.md#service-roles).


{% note info %}

To download an object group with a specified prefix (a [folder](../../concepts/object.md#folder) with objects) or all objects from a bucket, use the AWS CLI or file browsers compatible with the Amazon S3 API, such as [CyberDuck](../../tools/cyberduck.md) and [WinSCP](../../tools/winscp.md).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage**.
  1. Select the bucket from which you want to download an object.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/folder-tree.svg) **Objects** and find the object in the list.
  1. Next to the object you want to download, click ![image](../../../_assets/console-icons/ellipsis.svg) and select **Download** or open the object and click ![image](../../../_assets/console-icons/arrow-down-to-line.svg) **Download** in the top panel.

  {% note info %}

  You can also use [CyberDuck](../../tools/cyberduck.md) or [WinSCP](../../tools/winscp.md) to download or upload objects using the GUI.

  {% endnote %}

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for downloading an object from a bucket:
  
      ```bash
      yc storage s3api get-object --help
      ```
  
  1. Get a list of buckets in the default folder:
     
     ```bash
     yc storage bucket list
     ```
     
     Result:
     
     ```text
     +------------------+----------------------+-------------+-----------------------+---------------------+
     |       NAME       |      FOLDER ID       |  MAX SIZE   | DEFAULT STORAGE CLASS |     CREATED AT      |
     +------------------+----------------------+-------------+-----------------------+---------------------+
     | first-bucket     | b1gmit33ngp6******** | 53687091200 | STANDARD              | 2022-12-16 13:58:18 |
     +------------------+----------------------+-------------+-----------------------+---------------------+
     ```
  1. Run this command:
  
      ```bash
      yc storage s3api get-object \
        --bucket <bucket_name> \
        --key <object_key> \
        <download_path>
      ```
  
      Where:
  
      * `--bucket`: Name of your bucket.
      * `--key`: Object [key](../../concepts/object.md#key).
      * `<download_path>`: Local download path.
  
      Result:
  
      ```bash
      etag: '"d41d8cd98f00b204e9800998********"'
      request_id: af194b83********
      accept_ranges: bytes
      content_type: application/octet-stream
      last_modified_at: "2024-10-08T12:36:36Z"
      server_side_encryption: aws:kms
      sse_kms_key_id: abj497vtg3h0********
      ```
  
      Alternative command:
  
      ```bash
      yc storage s3 cp \
        s3://<bucket_name>/<object_key> \
        <download_path>
      ```
  
      Result:
  
      ```text
      download: s3://my-bucket/object.txt to object.txt
      ```
  
      {% cut "Configuring parameters for the `yc storage s3 cp` command" %}
  
      You can set the following parameters for the `yc storage s3 cp` command:
      
      * `s3.max-queue-size`: Maximum number of issues per queue. The default value is `1,000`.
      * `s3.max-concurrent-requests`: Maximum number of simultaneous requests. The default value is `10`.
      * `s3.multipart-threshold`: Object threshold size to trigger a multipart upload if exceeded. The default value is `8MB`.
      * `s3.multipart-chunksize`: Size of parts the object will be split into in a multipart upload. The default value is `8MB`.
      
      To set these parameters, use the `yc config set <parameter> <value>` command.
  
      {% endcut %}

- AWS CLI {#aws-cli}

  If you do not have the AWS CLI yet, [install and configure it](../../tools/aws-cli.md).

  **Downloading a single object**

  ```bash
  aws s3 cp \
    --endpoint-url=https://storage.yandexcloud.net \
    s3://<bucket_name>/<object_key> \
    <local_path>
  ```

  Where:

  * `--endpoint-url`: Object Storage endpoint.
  * `<bucket_name>`: Name of the bucket you want to download the object from.
  * `<object_key>`: [Key](../../concepts/object.md#key) of the object you want to download.
  * `<local_path>`: Path to the directory to save the downloaded object to, e.g., `~/downloads/`.

  **Downloading a folder (all objects with a specified prefix)**

  You can learn more about folders in Object Storage [Directory](../../concepts/object.md#folder) here.

  ```bash
  aws s3 cp \
    --endpoint-url=https://storage.yandexcloud.net \
    --recursive \
    s3://<bucket_name>/<prefix>/ \
    <local_path>
  ```

  Where:

  * `--endpoint-url`: Object Storage endpoint.
  * `--recursive`: Parameter for downloading all objects with the specified prefix.
  * `<bucket_name>`: Name of the bucket you want to download the objects from.
  * `<prefix>`: Prefix (folder) of the objects you want to download, e.g., `test/folder`.
  * `<local_path>`: Path to the directory to save the downloaded objects to, e.g., `~/downloads/`.

  **Downloading all objects from a bucket**

  ```bash
  aws s3 cp \
    --endpoint-url=https://storage.yandexcloud.net \
    --recursive \
    s3://<bucket_name> \
    <local_path>
  ```

  Where:

  * `--endpoint-url`: Object Storage endpoint.
  * `--recursive`: Parameter for downloading all objects from the bucket to a local directory.
  * `<bucket_name>`: Name of the bucket you want to download the objects from.
  * `<local_path>`: Path to the directory to save the downloaded objects to, e.g., `~/downloads/`.

  `aws s3 cp` is a high-level command providing limited features. For more information, see the [AWS CLI reference](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/cp.html).

  You can download bucket objects selectively using the `aws s3api` command and a JMESPath query template. To download objects using a query template, run this command:

  * **Bash**:

      ```bash
      aws s3api list-objects \
          --endpoint-url https://storage.yandexcloud.net \
          --bucket <bucket_name> \
          --query '<query>' \
          --output text | xargs -I {} aws s3api get-object --endpoint-url https://storage.yandexcloud.net --bucket <bucket_name> --key {} <local_path>{}
      ```

      Where:

      * `--endpoint-url`: Object Storage endpoint.
      * `--bucket`: Name of the bucket you want to download the objects from.
      * `--query`: Query in [JMESPath](https://jmespath.org/) format.
      * `<local_path>`: Path to the directory to save the downloaded objects to, e.g., `~/downloads/`.

      Here is an example of a command that downloads all objects whose filenames start with `date-20231002` from the bucket named `sample-bucket` to the `~/downloads/` local directory:

      ```bash
      aws s3api list-objects \
        --endpoint-url https://storage.yandexcloud.net \
        --bucket sample-bucket \
        --query 'Contents[?starts_with(Key, `date-20231002`) == `true`].[Key]' \
        --output text | xargs -I {} aws s3api get-object --endpoint-url https://storage.yandexcloud.net --bucket sample-bucket --key {} ~/downloads/{}
      ```

  * **PowerShell**:

      ```powershell
      Foreach($x in (aws s3api list-objects `
        --endpoint-url https://storage.yandexcloud.net `
        --bucket <bucket_name> `
        --query '<query>' `
        --output text)) `
        {aws s3api get-object --endpoint-url https://storage.yandexcloud.net --bucket <bucket_name> --key $x <local_path>$x}
      ```

      Where:

      * `--endpoint-url`: Object Storage endpoint.
      * `--bucket`: Name of the bucket you want to download the objects from.
      * `--query`: Query in [JMESPath](https://jmespath.org/) format.
      * `<local_path>`: Path to the directory to save the downloaded objects to, e.g., `d:\downloads\`.

      Here is an example of a command that downloads all objects whose filenames start with `date-20231002` from the bucket named `sample-bucket` to the `d:\downloads\` local directory:

      ```powershell
      Foreach($x in (aws s3api list-objects `
        --endpoint-url https://storage.yandexcloud.net `
        --bucket sample-bucket `
        --query 'Contents[?starts_with(Key, `date-20231002`) == `true`].[Key]' `
        --output text)) `
        {aws s3api get-object --endpoint-url https://storage.yandexcloud.net --bucket sample-bucket --key $x d:\downloads\$x}
      ```

- API {#api}

  To download an object, use the [get](../../s3/api-ref/object/get.md) S3 API method.

{% endlist %}

#### Useful links {#see-also}


* [Getting a pre-signed URL to download an object](link-for-download.md)
* [Access management methods in Object Storage: Overview](../../security/overview.md)