Skip to content

GCS Listing

In order to list files in Google Storage (GCS) bucket you need to execute connect list gcs followed by one mandatory parameter:

  • --bucket then the GCS bucket name

You can also provide an optional folder with:

  • -d, --folder then the folder

Depending on the type of authentication you need to either use --auth-json for key based authentication or use the service account assigned to the instance (if the server is running on GCP).

To use JSON key for the authentication you need to provide:

  • --auth-json then the path to the file containing the auth JSON

For example:

Terminal window
$ connect list gcs --auth-json /path/to/key-file.json --bucket my-gcs-bucket
2025/05/22 12:42:09 INFO Listing gcs://my-gcs-bucket/
d--------- 0 folder1/
-rw-rw-r-- 1024 Sep 15 21:27 file1.txt
-rw-rw-r-- 1024 Sep 15 21:27 file2.txt
-rw-rw-r-- 1024 Sep 15 21:27 file3.txt

To authenticate with Application Default Credentials (ADC) you need to set GOOGLE_APPLICATION_CREDENTIALS environment variable that points to the key file.

Terminal window
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key-file.json"

Then you can omit providing the key file as it will be obtained from the environment variable. For example:

Terminal window
$ connect list gcs --bucket my-gcs-bucket
2025/05/22 12:44:59 INFO Listing gcs://my-gcs-bucket/
d--------- 0 folder1/
-rw-rw-r-- 1024 Sep 15 21:27 file1.txt
-rw-rw-r-- 1024 Sep 15 21:27 file2.txt
-rw-rw-r-- 1024 Sep 15 21:27 file3.txt

For user credentials, ADC can be set by running Following

Terminal window
$ gcloud auth application-default login

Once authenticated you can connect without specifying the JSON key.

Terminal window
$ connect list gcs --bucket my-gcs-bucket
2025/05/22 12:45:10 INFO Listing gcs://my-gcs-bucket/
d--------- 0 folder1/
-rw-rw-r-- 1024 Sep 15 21:27 file1.txt
-rw-rw-r-- 1024 Sep 15 21:27 file2.txt
-rw-rw-r-- 1024 Sep 15 21:27 file3.txt

You can also specify the optional target folder to list with:

  • -d, --folder remote folder name

If you don’t specify the folder, the command will list root folder of the bucket.

For example:

Terminal window
$ connect list gcs --bucket my-gcs-bucket -d folder1
2025/05/22 12:51:33 INFO Listing gcs://my-gcs-bucket/folder1/
-rw-rw-r-- 0 May 22 12:50 folder1/
-rw-rw-r-- 1024 May 22 12:51 folder1/file1.txt
-rw-rw-r-- 1024 May 22 12:51 folder1/file2.txt
-rw-rw-r-- 1024 May 22 12:52 folder1/file3.txt
Terminal window
Usage:
connect list gcs [command] [flags]
Flags:
--auth-json string GCS authentication json file
--bucket string GCS bucket
Global Flags:
-d, --folder string Folder to list files
--godebug Turns on debug mode
--help Prints help for the command
--log-format string Log output format: text|json (default "text")
--no-color Do not use colors in logs
--quiet Makes no output

Please check here for information on the possible errors.