upx

package module
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 32 Imported by: 0

README

upx is a tool for managing files in UPYUN. Mac, Linux, Windows supported

Test Build Lint Go Report Card GitHub tag (latest by date)

基本功能

  • 支持基本文件系统操作命令,如 mkdir, cd, ls, rm, pwd
  • 支持上传文件或目录到又拍云存储
  • 支持从又拍云存储下载文件或目录到本地
  • 支持增量同步文件到又拍云存储
  • 支持删除又拍云存储中的文件或目录,并且支持通配符 *
  • 支持多用户,多操作系统
  • 支持基于时间列目录以及删除文件
  • 支持 tree 获取目录结构
  • 支持提交异步处理任务
  • 更加准确简洁的进度条
  • 使用 UPYUN GoSDK v3
  • 同步目录支持 --delete
  • 支持 CDN 缓存刷新

安装

可执行程序二进制下载地址

源码编译

需要安装 Golang 编译环境

$ git clone https://github.com/upyun/upx.git
$ cd upx && make

or

$ go get -u github.com/upyun/upx/cmd/upx@master

Windows

PS> scoop bucket add carrot https://github.com/upyun/carrot.git
Install upx from github or upyun cdn:
PS> scoop install upx-github
PS> scoop install upx-upcdn

Docker

docker build -t upx .
docker run --rm upx upx -v

使用

所有命令都支持 -h 查看使用方法

命令 说明
login 登录又拍云存储
logout 退出帐号
sessions 查看所有的会话
switch 切换会话
info 显示服务名、用户名等信息
ls 显示当前目录下文件和目录信息
cd 改变工作目录(进入一个目录)
pwd 显示当前所在目录
mkdir 创建目录
tree 显示目录结构
get 下载一个文件或目录
put 上传一个文件或目录
upload 上传多个文件或目录或 http(s) 文件, 支持 Glob 模式过滤上传文件
mv 在同一 bucket 内移动文件
cp 在同一 bucket 内复制文件
rm 删除目录或文件
sync 目录增量同步,类似 rsync
auth 生成包含空间名操作员密码信息的 auth 字符串
post 提交异步处理任务
purge 提交 CDN 缓存刷新任务
global options 说明
--quiet, -q 不显示信息
--auth value auth 字符串
--help, -h 显示帮助信息
--version, -v 显示版本号

login

使用又拍云操作员账号登录服务, 登录成功后将会保存会话,支持同时登录多个服务, 使用 switch 切换会话。

需要提供的验证字段

  • ServiceName: 服务(bucket)的名称
  • Operator: 操作员名
  • Password: 操作员密码
语法
upx login
示例
upx login

#ServiceName: testService
#Operator:  upx
#Password: password

logout

退出当前登录的会话,如果存在多个登录的会话,可以使用 switch 切换到需要退出的会话,然后退出。

语法
upx logout
示例
upx logout

# Goodbye upx/testService ~

sessions

列举出当前登录的所有会话

语法
upx sessions
示例
upx sessions

# > mybucket1
# > mybucket2
# > mybucket3

switch

切换登录会话, 通过 sessions 命令可以查看所有的会话列表。

args 说明
service-name 服务名称(bucket)
语法
upx switch <service-name>
示例
upx switch mybucket3

info

查看当前服务的状态。

语法
upx info
示例
upx info
> ServiceName:   mybucket1
> Operator:      tester
> CurrentDir:    /
> Usage:         2.69GB

ls

默认按文件修改时间先后顺序输出

args 说明
remote-path 远程路径
options 说明
-d 仅显示目录
-r 文件修改时间倒序输出
--color 根据文件类型输出不同的颜色
-c v 仅显示前 v 个文件或目录, 默认全部显示
--mtime v 通过文件被修改的时间删选,参考 Linux find
语法
upx ls [options...] [remote-path]
示例

查看根目录下的文件

upx ls /

只查看根目录下的目录

upx ls -d /

只查看根目录下的修改时间大于3天的文件

upx ls --mtime +3 /

只查看根目录下的修改时间小于1天的文件

upx ls --mtime -1 /

cd

改变当前的工作路径,默认工作路径为根目录, 工作路径影响到操作时的默认远程路径。

args 说明
remote-path 远程路径
语法
upx cd <remote-path>
示例

将当前工作路径切换到 /www

upx cd /www

pwd

显示当前所在的远程目录

语法
upx pwd
示例
upx pwd

> /www

mkdir

创建远程目录

args 说明
remote-dir 远程目录
语法
upx mkdir <remote-dir>
示例

在当前工作目录下创建一个名为 mytestbucket 的目录

upx mkdir mytestbucket

在根目录下创建一个名为 mytestbucket 的目录

upx mkdir /mytestbucket

tree

显示目录结构,树形模式显示

语法
upx tree
示例

查看 /ccc 目录下的目录结构

upx tree /ccc
> |-- aaacd
> !   |-- mail4788ca.png
> |-- ccc
> !   |-- Eroge de Subete wa Kaiketsu Dekiru! The Animation - 02 (2022) [1080p-HEVC-WEBRip][8D1929F5].mkv
> !   |-- baima_text_auditer.tar
> !   |-- linux-1.txt

get

下载文件

args 说明
remote-path 远程路径,支持文件或文件夹
saved-file 需要保存到的本地目录,或指定完整的文件名
options 说明
-w 多线程下载 (1-10) (default: 5)
-c 恢复中断的下载
--start 只下载路径字典序大于等于 start 的文件或目录
--end 只下载路径字典序小于 end 的文件或目录
语法
upx get [options] <remote-path> [saved-file]
示例

下载文件

upx get /baima_text_auditer.tar

下载文件时指定保存路径

upx get /baima_text_auditer.tar ./baima_text_auditer2.tar

多线程下载文件

upx get -w 10 /baima_text_auditer.tar

恢复中断的下载

upx get -c /baima_text_auditer.tar

put

上传文件或文件夹

args 说明
local-file 本地的文件或文件夹
url 远端 url 文件
remote-file 需要保存到的远程文件路径或文件夹
options 说明
-w 多线程下载 (1-10) (default: 5)
-all 上传包含目录下隐藏的文件和文件夹
语法
upx put <local-file>|<url> [remote-file]
示例

上传本地文件,到远程绝对路径

upx put aaa.mp4 /video/aaa.mp4

上传本地目录,到远程绝对路径

upx put ./video /myfiles

上传 url 文件,到远程绝对路径

 upx put https://xxxx.com/myfile.tar.gz /myfiles

upload

上传文件或目录,支持多文件,文件名匹配

args 说明
local-file 本地的文件或文件夹, 或匹配文件规则
remote-path 需要保存到的远程文件路径
options 说明
-w 多线程下载 (1-10) (default: 5)
-all 上传包含目录下隐藏的文件和文件夹
--remote 远程路径
语法
upx upload [--remote remote-path] <local-file>
示例

上传当前路径下的所有 jpg 图片到 /images 目录

upx upload --remote /images ./*.jpg

rm

默认不会删除目录,支持通配符 *

args 说明
remote-file 远程文件
options 说明
-d 仅删除目录
-a 删除目录跟文件
--async 异步删除,目录可能需要二次删除
--mtime v 参考 Linux find
语法
upx rm [options] <remote-file>
示例

删除目录 /www

upx rm -d /www

删除文件 /aaa.png

upx rm /aaa.png

mv

bucket 内部移动文件

args 说明
source-file 需要移动的源文件
dest-file 需要移动到的目标文件
options 说明
-f 允许覆盖目标文件
语法
upx mv [options] <source-file> <dest-file>
示例

移动文件

upx mv /aaa.mp4 /abc/aaa.mp4

移动文件,如果目标存在则强制覆盖

upx mv -f /aaa.mp4 /abc/aaa.mp4

cp

bucket 内部拷贝文件

args 说明
source-file 需要复制的源文件
dest-file 需要复制到的目标文件
options 说明
-f 允许覆盖目标文件
语法
upx mv [options] <source-file> <dest-file>
示例

移动文件

upx cp /aaa.mp4 /abc/aaa.mp4

复制文件,如果目标存在则强制覆盖

upx cp -f /aaa.mp4 /abc/aaa.mp4

sync

sync 本地路径 存储路径

args 说明
local-path 本地的路径
remote-path 远程文件路径
options 说明
-w 指定并发数,默认为 5
--delete 删除上一次同步后本地删除的文件
语法
upx sync <local-path> <remote-path>
示例

同步本地路径和远程路径

upx sync ./workspace /workspace

auth

生成包含空间名操作员密码信息, auth 空间名 操作员 密码

示例

当命令中包含 --auth 参数时,会忽略已登陆的信息。

生成 auth 字符串

upx auth mybucket user password

通过生成的 auth 字符串上传文件

upx --auth=auth-string put temp.file

post

options 说明
--app value app 名称
--notify value 回调地址
--task value 任务文件名

purge

purge url --list urls

options 说明
--list value 批量刷新文件名

TODO

  • put 支持断点续传
  • upx 支持指定 API 地址

Documentation

Index

Constants

View Source
const (
	NO_CHECK = false
	CHECK    = true
)
View Source
const (
	LOGIN     = true
	NO_LOGIN  = false
	MinJitter = 5
	MaxJitter = 60
	MaxRetry  = 10
)
View Source
const (
	TIME_NOT_SET = iota
	TIME_BEFORE
	TIME_AFTER
	TIME_INTERVAL
)
View Source
const (
	ITEM_NOT_SET = iota
	DIR
	FILE
)
View Source
const (
	SYNC_EXISTS = iota
	SYNC_OK
	SYNC_FAIL
	SYNC_NOT_FOUND
	DELETE_OK
	DELETE_FAIL

	MinResumePutFileSize = 100 * 1024 * 1024
	DefaultBlockSize     = 10 * 1024 * 1024
	DefaultResumeRetry   = 10
)
View Source
const (
	VERSION_URL         = "https://raw.githubusercontent.com/upyun/upx/master/VERSION"
	DOWNLOAD_URL_PREFIX = "http://collection.b0.upaiyun.com/softwares/upx/upx-"
)
View Source
const VERSION = "v0.4.6"

Variables

View Source
var (
	IsVerbose = true
)

Functions

func ChmodAndRename

func ChmodAndRename(src, dst string) error

func CreateInitCheckFunc added in v0.3.8

func CreateInitCheckFunc(login, check bool) cli.BeforeFunc

func CreateUpxApp added in v0.3.8

func CreateUpxApp() *cli.App

func DownloadBin

func DownloadBin(version, binPath string) error

func GetCurrentBinPath

func GetCurrentBinPath() string

func GetLatestVersion

func GetLatestVersion() (string, error)

func InitAndCheck

func InitAndCheck(login, check bool, c *cli.Context) (err error)

func IsMatched

func IsMatched(upInfo *upyun.FileInfo, mc *MatchConfig) bool

func NewAuthCommand

func NewAuthCommand() cli.Command

func NewCdCommand

func NewCdCommand() cli.Command

func NewCleanDBCommand added in v0.3.8

func NewCleanDBCommand() cli.Command

func NewCopyCommand added in v0.4.1

func NewCopyCommand() cli.Command

func NewFileWrappedReader added in v0.4.3

func NewFileWrappedReader(bar *mpb.Bar, fd io.ReadCloser) io.ReadCloser

func NewFileWrappedWriter

func NewFileWrappedWriter(localPath string, bar *mpb.Bar, resume bool) (io.WriteCloser, error)

func NewGetCommand

func NewGetCommand() cli.Command

func NewGetDBCommand

func NewGetDBCommand() cli.Command

func NewInfoCommand

func NewInfoCommand() cli.Command

func NewListSessionsCommand

func NewListSessionsCommand() cli.Command

func NewLoginCommand

func NewLoginCommand() cli.Command

func NewLogoutCommand

func NewLogoutCommand() cli.Command

func NewLsCommand

func NewLsCommand() cli.Command

func NewMkdirCommand

func NewMkdirCommand() cli.Command

func NewMoveCommand added in v0.4.1

func NewMoveCommand() cli.Command

func NewPostCommand

func NewPostCommand() cli.Command

func NewPurgeCommand

func NewPurgeCommand() cli.Command

func NewPutCommand

func NewPutCommand() cli.Command

func NewPwdCommand

func NewPwdCommand() cli.Command

func NewRmCommand

func NewRmCommand() cli.Command

func NewSwitchSessionCommand

func NewSwitchSessionCommand() cli.Command

func NewSyncCommand

func NewSyncCommand() cli.Command

func NewTreeCommand

func NewTreeCommand() cli.Command

func NewUpgradeCommand

func NewUpgradeCommand() cli.Command

func NewUploadCommand added in v0.3.8

func NewUploadCommand() cli.Command

func Print

func Print(arg0 string, args ...interface{})

func PrintError

func PrintError(arg0 string, args ...interface{})

func PrintErrorAndExit

func PrintErrorAndExit(arg0 string, args ...interface{})

func PrintOnlyVerbose

func PrintOnlyVerbose(arg0 string, args ...interface{})

func Upgrade

func Upgrade()

Types

type Config

type Config struct {
	SessionId int        `json:"user_idx"`
	Sessions  []*Session `json:"users"`
}

func (*Config) Insert

func (c *Config) Insert(sess *Session)

func (*Config) PopCurrent

func (c *Config) PopCurrent()

type MatchConfig

type MatchConfig struct {
	Wildcard string

	TimeType int
	Before   time.Time
	After    time.Time

	Start string
	End   string

	ItemType int
}

type Session

type Session struct {
	Bucket   string `json:"bucket"`
	Operator string `json:"username"`
	Password string `json:"password"`
	CWD      string `json:"cwd"`
	// contains filtered or unexported fields
}

func (*Session) AbsPath

func (sess *Session) AbsPath(upPath string) (ret string)

func (*Session) Cd

func (sess *Session) Cd(upPath string)

func (*Session) Copy added in v0.4.1

func (sess *Session) Copy(srcPath, destPath string, force bool) error

func (*Session) FormatUpInfo

func (sess *Session) FormatUpInfo(upInfo *upyun.FileInfo) string

func (*Session) Get

func (sess *Session) Get(upPath, localPath string, match *MatchConfig, workers int, resume bool)

func (*Session) GetStartBetweenEndFiles added in v0.3.8

func (sess *Session) GetStartBetweenEndFiles(upPath, localPath string, match *MatchConfig, workers int)

func (*Session) Info

func (sess *Session) Info()

func (*Session) Init

func (sess *Session) Init() error

func (*Session) IsLocalDir

func (sess *Session) IsLocalDir(localPath string) (isDir bool, exist bool)

func (*Session) IsUpYunDir

func (sess *Session) IsUpYunDir(upPath string) (isDir bool, exist bool)

func (*Session) Ls

func (sess *Session) Ls(upPath string, match *MatchConfig, maxItems int, isDesc bool)

func (*Session) Mkdir

func (sess *Session) Mkdir(upPaths ...string)

func (*Session) Move added in v0.4.1

func (sess *Session) Move(srcPath, destPath string, force bool) error

func (*Session) PostTask

func (sess *Session) PostTask(app, notify, taskFile string)

func (*Session) Purge

func (sess *Session) Purge(urls []string, file string)

func (*Session) Put

func (sess *Session) Put(localPath, upPath string, workers int, withIgnore bool)

/ Put 上传单文件或单目录

func (*Session) Pwd

func (sess *Session) Pwd()

func (*Session) Rm

func (sess *Session) Rm(upPath string, match *MatchConfig, isAsync bool)

func (*Session) Sync

func (sess *Session) Sync(localPath, upPath string, workers int, delete, strong bool)

func (*Session) Tree

func (sess *Session) Tree(upPath string)

func (*Session) Upload added in v0.3.8

func (sess *Session) Upload(filenames []string, upPath string, workers int, withIgnore bool)

put 的升级版命令, 支持多文件上传

type UploadedFile added in v0.3.8

type UploadedFile struct {
	LocalPath string
	UpPath    string
	LocalInfo os.FileInfo
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cmd
upx

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL