# SFTPGo 生命週期管理 (Source → Install → Config → Use)
**Date**: 2026-05-15
**Status**: Active, Verified
---
## 生命週期總覽
```
Source → Archive → Build → Install → Config → Start → Verify → Use
① ② ③ ④ ⑤ ⑥ ⑦ ⑧
```
---
## ① Source Code
| Field | Value |
|-------|-------|
| **Repository** | `https://github.com/drakkan/sftpgo.git` |
| **Branch** | `main` (commit `6e543c6`) |
| **License** | AGPL v3 |
| **Language** | Go 1.26+ |
| **Go files** | 246 |
| **Source size** | 23 MB |
## ② Archive
```bash
# Archive command
cd /tmp
tar czf release/system/v1.0/services/src/sftpgo-main.tar.gz sftpgo/
# Verify
shasum -a 256 release/system/v1.0/services/src/sftpgo-main.tar.gz
# → 6607334148917dd80a687706a3ae63ea8c532d10c6717c87491da23939c96d4a
```
**Archive location**: `release/system/v1.0/services/src/sftpgo-main.tar.gz` (9.2 MB)
## ③ Build
```bash
# Clone source
git clone --depth 1 https://github.com/drakkan/sftpgo.git /tmp/sftpgo
# Build binary
cd /tmp/sftpgo
go build -o /Users/accusys/bin/sftpgo .
# Verify binary
shasum -a 256 /Users/accusys/bin/sftpgo
# → 9991d2a1c877d5bcae17cb4e026de939862e4b880924589cf4ed15ac7291ec7e
ls -lh /Users/accusys/bin/sftpgo
# → 88 MB
```
**Binary**: `/Users/accusys/bin/sftpgo` (88 MB)
## ④ Install
### Database
```bash
# Create dedicated PostgreSQL database + user
psql -U accusys -h /tmp -d postgres -c "CREATE DATABASE sftpgo"
psql -U accusys -h /tmp -d postgres -c "CREATE USER sftpgo WITH PASSWORD 'sftpgo_pass_2026'"
psql -U accusys -h /tmp -d sftpgo -c "GRANT ALL ON SCHEMA public TO sftpgo"
```
### Templates & Static Files
```bash
# Copy from source (required by SFTPGo)
cp -r /tmp/sftpgo/templates/ /Users/accusys/momentry/etc/sftpgo/templates/
cp -r /tmp/sftpgo/static/ /Users/accusys/momentry/etc/sftpgo/static/
cp -r /tmp/sftpgo/openapi/ /Users/accusys/momentry/etc/sftpgo/openapi/
```
## ⑤ Configuration
**Config file**: `/Users/accusys/momentry/etc/sftpgo/sftpgo.json`
### Key Settings
| Section | Key | Value |
|---------|-----|-------|
| `data_provider` | `driver` | `postgresql` |
| `data_provider` | `name` | `sftpgo` |
| `data_provider` | `users_base_dir` | `/Users/accusys/momentry/var/sftpgo/data` |
| `httpd.bindings[0]` | `port` | `8080` |
| `sftpd.bindings[0]` | `port` | `2022` |
| `webdavd.bindings[0]` | `port` | `8090` |
### launchd Plist
**File**: `momentry_runtime/plist/com.momentry.sftpgo.plist`
```xml
ProgramArguments
/Users/accusys/bin/sftpgo
serve
-c
/Users/accusys/momentry/etc/sftpgo/
```
## ⑥ Start
### Initialize Provider (first time only)
```bash
SFTPGO_DEFAULT_ADMIN_USERNAME=admin \
SFTPGO_DEFAULT_ADMIN_PASSWORD=Test3200Test3200 \
/Users/accusys/bin/sftpgo initprovider -c /Users/accusys/momentry/etc/sftpgo/
```
### Start Serve
```bash
SFTPGO_DEFAULT_ADMIN_USERNAME=admin \
SFTPGO_DEFAULT_ADMIN_PASSWORD=Test3200Test3200 \
nohup /Users/accusys/bin/sftpgo serve \
-c /Users/accusys/momentry/etc/sftpgo/ \
> /Users/accusys/momentry/log/sftpgo.log 2>&1 &
```
## ⑦ Verify
```bash
# Service check
curl -sI http://localhost:8080/
# → Server: SFTPGo/2.7.99-dev
# HTTPS
curl -sI https://m5sftpgo.momentry.ddns.net/
# → Server: SFTPGo/2.7.99-dev
# → Via: 1.1 Caddy
# Auth
curl -s -u "admin:Test3200Test3200" http://localhost:8080/api/v2/token
# → {"access_token":"eyJ...","expires_at":"..."}
```
## ⑧ Usage
### User Management
**Admin**: `admin` / `Test3200Test3200`
**Demo user**: `demo` / `demopassword123`
```bash
# Get admin token
TOKEN=$(curl -s -u "admin:Test3200Test3200" \
"http://localhost:8080/api/v2/token" | \
python3 -c "import json,sys;print(json.load(sys.stdin).get('access_token',''))")
# Create user
curl -s -X POST "http://localhost:8080/api/v2/users" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"username":"demo","password":"demopassword123",
"home_dir":"/Users/accusys/momentry/var/sftpgo/data/demo",
"permissions": {"/": ["*"]}, "status": 1}'
# Update user password
curl -s -X PUT "http://localhost:8080/api/v2/users" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$(curl -s http://localhost:8080/api/v2/users -H 'Authorization: Bearer $TOKEN' | python3 -c \"import json,sys;u=[u for u in json.load(sys.stdin) if u['username']=='demo'][0];u['password']='newpass';print(json.dumps(u))\")"
# List users
curl -s "http://localhost:8080/api/v2/users" \
-H "Authorization: Bearer $TOKEN"
```
### External Access
```bash
# Via HTTPS
curl -s "https://m5sftpgo.momentry.ddns.net/api/v2/status"
# SFTP (port 2022)
sftp -P 2022 demo@m5sftpgo.momentry.ddns.net
# WebDAV (port 8090)
# http://m5sftpgo.momentry.ddns.net:8090/
```
---
## 資源管理記錄
### dev.resources
```sql
INSERT INTO dev.resources (resource_id, resource_type, category, capabilities, config)
VALUES (
'sftpgo', 'system_tool', 'file_upload',
'["sftp", "file_transfer", "webdav"]',
'{"binary": "/Users/accusys/bin/sftpgo",
"version": "2.7.99-dev",
"port": 8080,
"source_sha256": "6607334148917dd80a687706a3ae63ea8c532d10c6717c87491da23939c96d4a",
"binary_sha256": "9991d2a1c877d5bcae17cb4e026de939862e4b880924589cf4ed15ac7291ec7e",
"source_archive": "release/system/v1.0/services/src/sftpgo-main.tar.gz",
"plist": "momentry_runtime/plist/com.momentry.sftpgo.plist"}'
)
ON CONFLICT (resource_id) DO UPDATE SET
resource_type = EXCLUDED.resource_type,
category = EXCLUDED.category,
config = EXCLUDED.config;
```
---
## SHA256 Checksums Reference
| Asset | SHA256 |
|-------|--------|
| Source archive (`sftpgo-main.tar.gz`) | `6607334148917dd80a687706a3ae63ea8c532d10c6717c87491da23939c96d4a` |
| Binary (`/Users/accusys/bin/sftpgo`) | `9991d2a1c877d5bcae17cb4e026de939862e4b880924589cf4ed15ac7291ec7e` |
---
## Ports Summary
| Port | Protocol | Service | External URL |
|------|----------|---------|-------------|
| 8080 | HTTP | Web Admin + REST API | `https://m5sftpgo.momentry.ddns.net` |
| 2022 | SFTP | File Transfer | `sftp://m5sftpgo.momentry.ddns.net:2022` |
| 8090 | WebDAV | File Access | `https://m5sftpgo.momentry.ddns.net:8090/` |