Download and upload files and folders between GCS and Cloud Shell

I have some files and folders on GCS(Google Cloud Storage):

enter image description here

And I have some files and folders on Cloud Shell as well:

enter image description here

Now, I want to download and upload these files and folders between GCS and Cloud Shell:

Are there any ways to do that?

Upvotes: 0

Views: 1864

Answers (2)

--- Download files and folders from GCS to Cloud Shell ---

Hint:

gsutil cp gs://<GCS_Bucket_Name>/<File_Name> <Cloud_Shell_Directory>

This downloads "one file" on GCS to current directory on Cloud Shell:

gsutil cp gs://test.com/file1.json .

This downloads "two files" on GCS to current directory on Cloud Shell:

gsutil cp gs://test.com/file1.json gs://test.com/file2.txt .

This downloads "one file" and "one folder" on GCS to current directory on Cloud Shell:

(Hint-1: "-r" is needed to download folders)
(Hint-2: If a folder is empty, the folder is not downloaded)

gsutil cp -r gs://test.com/file1.json gs://test.com/folder1 .

--- Upload files and folders from Cloud Shell to GCS: ---

Hint:

gsutil cp <Cloud_Shell_File> gs://<GCS_Bucket_Name>

This uploads "one file" on Cloud Shell to GCS:

gsutil cp file1.json gs://test.com

This uploads "two files" on Cloud Shell to GCS:

gsutil cp file1.json file2.txt gs://test.com

This uploads "one file" and "one folder" on Cloud Shell to GCS:

(Hint-1: "-r" is needed to upload folders)
(Hint-2: If a folder is empty, the folder is not uploaded)

gsutil cp -r file1.json folder1 gs://test.com

Upvotes: 0

Akshansha Singhal
Akshansha Singhal

Reputation: 862

You can download the objects from the buckets in the Cloud Storage using gsutil cp command in the cloud shell:

gsutil cp gs://BUCKET_NAME/OBJECT_NAME SAVE_TO_LOCATION

Also, you can download the files using the console by clicking on the Download icon associated with the object and upload it to the cloud shell.

For more information, refer to the documentation.

Upvotes: 1

Related Questions