CDNetworks Documentation Object Storage Tutorials Sync local files to OS by cli

Sync local files to OS by cli

Last update:2025-06-30 17:29:52

This chapter will introduce how to use the s3cmd tool to synchronize local files to object storage.

Prerequisites

  • Activate CDNetworks Object Storage service
  • Have already created storage space (Bucket)

Steps

Install s3cmd

Choose one of the following commands according to your operating system to execute:

# CentOS/RHEL system
Yum installation: sudo yum install s3cmd
# Debian/Ubuntu system
APT installation: sudo apt-get install s3cmd

Configure s3cmd

Execute the configuration command and fill in the information as prompted:

s3cmd --configure

Configuration Example
Edit the generated ~/.s3cfg file (or enter directly during the configuration process). Refer to the content below:

[default]
access_key = 5f5a1ca5xxxxxxxxxacf61afda42
host_base = s3-cn-east-2.wcsapi.com
host_bucket = %(bucket)s.s3-cn-east-2.wcsapi.com
secret_key = 4f32262xxxxxxxxxxxxcbbc7269a8c9

... (the rest of the default configuration is not posted)

Note:

  • A ~/.s3cfg file will be automatically generated in the user directory upon configuration completion
  • You need to replace access_key and secret_key with your actual keys
  • For more configuration parameter descriptions, use s3cmd -h

Perform File Synchronization

Basic synchronization command:

s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX]

Examples for common scenarios:

  1. If you want to fully sync files from E:\videos\ to the my-bucket space and retain the videos prefix, you can execute
1. Use relative path: first cd into E:\videos\ then: s3cmd sync . s3://my-bucket/videos/
2. Use absolute path: s3cmd sync E:\videos\. s3://my-bucket/videos/
  1. Debug mode, only print debug information
# Output detailed operation information
s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX] --debug
  1. Upload a single file
s3cmd put localPath s3://my-bucket/keyName
  1. More parameter descriptions
# View the full list of commands
s3cmd -h
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!