Using the s3cmd Client (S3)
With the s3cmd client you can easily interact with your Object Storage. Below you will find practical examples on how to use the client for your bucket at storage.netways.cloud.
Prerequisites
- You have a User with an S3 key (Access Key and Secret Key).
- The s3cmd client is installed on your system. If not, install it via your package manager or from s3tools.org.
Configuring the s3cmd Client
1. Create a configuration
Create a configuration for your NWS storage so you don’t have to enter credentials each time:
Follow the prompts and enter your credentials:
- Access Key:
ACCESS_KEY - Secret Key:
SECRET_KEY - Region:
default - Endpoint:
storage.netways.cloud - DNS‑style template:
%(bucket)s.storage.netways.cloud - Use HTTPS:
Y
Basic Examples
1. List buckets
Show all buckets in your project:
2. Upload a file
Upload a local file to your bucket:
3. List bucket contents
Show all files in a bucket:
4. Sync a directory
Synchronize a local directory with your bucket:
5. Download a file
Download a file from the bucket:
6. Delete files
Delete a file from the bucket:
7. Show file statistics
Display details about a file:
8. Create a public link
Generate a temporary download link (valid for 1 hour by default):
9. Create a bucket
Basic Commands for Bucket Policies
To manage public (anonymous) access you need to use the ACL commands:
1. Show current ACL
2. Set ACL
Examples for Common ACL Scenarios
ACL Types
The s3cmd client supports the following predefined ACL types:
privatepublic
1. Allow public access
2. Allow public access for all files
3. Remove all public access
4. Set ACL for a specific prefix
JSON‑Based Policy Management
1. Apply a JSON policy to a bucket
2. Read the current policy
3. Delete the current policy
Example JSON Policies
Example 1: Read access for specific IP ranges
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::my-bucket/*"],
"Condition": {
"IpAddress": {"aws:SourceIp": ["192.0.2.0/24"]}
}
}
]
}
Example 2: Time‑limited access
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::my-bucket/public/*"],
"Condition": {
"DateLessThan": {"aws:CurrentTime": "2023-12-31T23:59:59Z"}
}
}
]
}
Tips & Hints
Security notes
- Public rights (
public) should only be used in exceptional cases - Regularly review policies for necessity
- Combine policies with bucket quotas to limit unwanted usage
- Always validate JSON policies for correctness
- Test new policies first in non‑production environments
Debugging
Add the --debug flag to your commands to get detailed information if something does not work as expected.
Bucket Versioning
Enable versioning
Check versioning status
Suspend versioning
Object Lifecycle Management
Create lifecycle rules
Create an XML configuration file (lifecycle.xml):
<LifecycleConfiguration>
<Rule>
<ID>AutoDeleteTempFiles</ID>
<Filter>
<Prefix>temp/</Prefix>
</Filter>
<Status>Enabled</Status>
<Expiration>
<Days>7</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
Apply the rule:
Manage lifecycle rules
```bash
Show existing rules
s3cmd getlifecycle s3://my-bucket
Delete a rule
s3cmd dellifecycle s3://my-bucket