0

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?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
  • 1
    What about using gsutil from the Cloud Shell command line? Perhaps the gsutil cp command? – Kolban Nov 08 '21 at 17:59
  • OK, I'll try that. It's actually "copy" rather than "download". I see. – Super Kai - Kazuya Ito Nov 08 '21 at 18:05
  • Why do you want to do that? What's your use case? – guillaume blaquiere Nov 08 '21 at 21:27
  • "Why I want to do this" is to delete too many unnecessary files on GCS at once at the same time using ".txt" file that lists unnecessary files on Cloud Shell. I'm going to put the ".txt" file on GCS, then, when I want to delete unnecessary files, I'm going to download the ".txt" file from GCS to Cloud Shell, then, delete them with the ".txt" file running some command. – Super Kai - Kazuya Ito Nov 09 '21 at 04:41

2 Answers2

1

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.

0

--- 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
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129