pip
命令进行安装:pip install coscmd
-v
或者 --version
命令查看当前的版本信息。C:\\python_install_dir;
和 C:\\python_install_dir\\Scripts
两个路径加入到环境变量中。 pip install coscmd -U
git clone https://github.com/tencentyun/coscmd.gitcd coscmdpython setup.py install
# 在有外网的机器下运行如下命令mkdir coscmd-packagespip download coscmd -d coscmd-packagestar -czvf coscmd-packages.tar.gz coscmd-packages# 将安装包拷贝到没有外网的机器后运行如下命令tar -xzvf coscmd-packages.tar.gzpip install coscmd --no-index -f coscmd-packages
-h
或 --help
命令来查看工具的 help 信息和用法。coscmd -h
usage: coscmd [-h] [-d] [-s] [-b BUCKET] [-r REGION] [-c CONFIG_PATH][-l LOG_PATH] [--log_size LOG_SIZE][--log_backup_count LOG_BACKUP_COUNT] [-v]{config,upload,download,delete,abort,copy,move,list,listparts,info,restore,signurl,createbucket,deletebucket,putobjectacl,getobjectacl,putbucketacl,getbucketacl,putbucketversioning,getbucketversioning,probe}...an easy-to-use but powerful command-line tool. try 'coscmd -h' to get moreinformations. try 'coscmd sub-command -h' to learn all command usage, likes'coscmd upload -h'positional arguments:{config,upload,download,delete,abort,copy,move,list,listparts,info,restore,signurl,createbucket,deletebucket,putobjectacl,getobjectacl,putbucketacl,getbucketacl,putbucketversioning,getbucketversioning,probe}config Config your information at firstupload Upload file or directory to COSdownload Download file from COS to localdelete Delete file or files on COSabort Aborts upload parts on COScopy Copy file from COS to COSmove move file from COS to COSlist List files on COSlistparts List upload partsinfo Get the information of file on COSrestore Restoresignurl Get download urlcreatebucket Create bucketdeletebucket Delete bucketputobjectacl Set object aclgetobjectacl Get object aclputbucketacl Set bucket aclgetbucketacl Get bucket aclputbucketversioningSet the versioning stategetbucketversioningGet the versioning stateprobe Connection testoptional arguments:-h, --help show this help message and exit-d, --debug Debug mode-s, --silence Silence mode-b BUCKET, --bucket BUCKETSpecify bucket-r REGION, --region REGIONSpecify region-c CONFIG_PATH, --config_path CONFIG_PATHSpecify config_path-l LOG_PATH, --log_path LOG_PATHSpecify log_path--log_size LOG_SIZE specify max log size in MB (default 1MB)--log_backup_count LOG_BACKUP_COUNTspecify log backup num-v, --version show program's version number and exit
-h
查看该命令的具体用法,例如:coscmd upload -h //查看 upload 命令使用方法
~/.cos.conf
中读取配置项。[common]secret_id = AKIDA6wUmImTMzvXZNbGLCgtusZ2E8mG****secret_key = TghWBCyf5LIyTcXCoBdw1oRpytWk****bucket = configure-bucket-1250000000region = ap-chengdumax_thread = 5part_size = 1retry = 5timeout = 60schema = httpsverify = md5anonymous = False
timeout
项,单位为秒,指读写数据的超时时间。schema
项,可选值为 http、https,默认为 https。anonymous
项,可选值为 True、False,表示是否使用匿名模式,即签名保持为空。coscmd config -h
查看。~/.cos.conf
自动生成配置文件,命令具体格式如下:coscmd config [OPTION]...<FILE>...[-h] --help[-a] <SECRET_ID>[-s] <SECRET_KEY>[-t] <TOKEN>[-b] <BucketName-APPID>[-r] <REGION> | [-e] <ENDPOINT>[-m] <MAX_THREAD>[-p] <PART_SIZE>[--do-not-use-ssl][--anonymous]
选项 | 参数说明 | 有效值 | 是否必选 |
-a | 字符串 | 是 | |
-s | 字符串 | 是 | |
-t | 临时密钥 token,当使用临时密钥时需要配置,设置 x-cos-security-token 头部 | 字符串 | 否 |
-b | 字符串 | 是 | |
-r | 存储桶所在地域,请参见 地域和访问域名 | 字符串 | 是 |
-e | 设置请求的 ENDPOINT,设置 ENDPOINT 参数后,REGION 参数会失效。当您使用的是默认域名,则此处配置格式为 cos.<region>.myqcloud.com ;当您使用全球加速域名,则配置为 cos.accelerate.myqcloud.com | 字符串 | 否 |
-m | 多线程操作的最大线程数(默认为5)。如果上传文件缓慢,可适当调高该值。线程数取决于机器性能,假设机器支持最大线程数为30,则将并发线程调整为30,可充分利用机器性能,执行命令为 coscmd config -m 30 。 | 数字 | 否 |
-p | 分块操作的单块大小(单位MB,默认为1MB,范围为1 - 1000)。如果上传文件缓慢,可适当调高该值。 | 数字 | 否 |
--do-not-use-ssl | 使用 HTTP 协议,而不使用 HTTPS | 字符串 | 否 |
--anonymous | 匿名操作(不携带签名) | 字符串 | 否 |
coscmd config -a AChT4ThiXAbpBDEFGhT4ThiXAbp**** -s WE54wreefvds3462refgwewe**** -b configure-bucket-1250000000 -r ap-chengdu
-b <BucketName-APPID>
参数指定存储桶名称,存储桶的命名格式为 BucketName-APPID,此处填写的存储桶名称必须为此格式。-r <region>
指定 Region, 可以指定存储桶的所属地域。coscmd -b <BucketName-APPID> -r <region> <action> ...
coscmd -b examplebucket-1250000000 -r ap-beijing createbucket
coscmd -b examplebucket-1250000000 -r ap-beijing upload D:/picture.jpg /
~/.cos.conf
。若不指定日志文件的路径,则会使用默认的日志文件路径 ~/.cos.log
。-c <conf_path>
参数指定配置文件路径,COSCMD 在运行时会从此路径读取配置信息。-l <log_conf>
参数指定日志路径,COSCMD 会将运行过程中产生的日志输出到此路径下的日志文件中。coscmd -c <conf_path> -l <log_conf> <action> ...
coscmd -c /data/home/cos_conf -l /data/home/cos_log -b examplebucket-1250000000 -r ap-beijing createbucket
-d
或者 --debug
,在命令执行的过程中,会显示详细的操作信息 。示例如下:coscmd -d upload <localpath> <cospath>
coscmd -d upload -rs D:/folder/ /
-s
或者 --silence
,在命令执行的过程中,将不会再输出任何信息 。coscmd -s upload <localpath> <cospath>
coscmd -s upload D:/picture.jpg /
-b <BucketName-APPID>
指定存储桶名称和 -r <Region>
指定所属地域。若直接执行 coscmd createbucket,则会报错,原因是不指定存储桶名称和所属地域,则相当于对已存在的存储桶(即配置参数时所填的存储桶)进行创建。coscmd -b <BucketName-APPID> createbucket
coscmd -b examplebucket-1250000000 -r ap-beijing createbucket
coscmd deletebucket
的用法仅对配置参数时的存储桶有效。建议配合 -b <BucketName-APPID>
指定 Bucket 和 -r <region>
指定 Region 使用。coscmd -b <BucketName-APPID> deletebucket
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket -f
-f
参数则会强制删除该存储桶,包括所有文件、开启版本控制之后历史文件夹、上传产生的碎片,请谨慎操作。coscmd upload <localpath> <cospath>
coscmd upload D:/picture.jpg doc/
coscmd upload D:/doc/picture.jpg doc/
coscmd upload D:/picture.jpg doc/ -H "{'x-cos-storage-class':'Archive'}"
coscmd upload -H "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
。更多头部可参见 PUT Object 文档。coscmd upload D:/picture.jpg doc/ -H "{'x-cos-meta-example':'example'}"
coscmd upload D:/doc/file.zip doc/ -H "{'x-cos-traffic-limit':'819200'}"
coscmd upload -r <localpath> <cospath>
coscmd upload -r D:/doc /
coscmd upload -r D:/doc doc
coscmd upload -rs D:/doc doc
coscmd upload -rs --skipmd5 D:/doc doc
coscmd upload -rs --delete D:/doc /
coscmd upload -rs D:/doc / --ignore *.txt,*.doc
coscmd upload -rs D:/doc / --ignore "*.txt"
--ignore
参数可以忽略某一类文件,使用 --include
参数可以过滤某一类文件,支持 shell 通配规则,支持多条规则,用逗号 ,
分隔。当忽略一类后缀时,必须最后要输入 ,
或者加入 ""
。如果 ""
中包含多条逗号分隔的规则,以第一条规则为准。--ignore
过滤特定文件夹内的所有文件,需要使用绝对路径,并在路径前后加入 ""
。例如 coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*"
。coscmd upload -rs D:/doc / --include *.txt,*.doc
coscmd upload -rs D:/doc / --include "*.txt"
coscmd upload <localpath> <cospath>
。x-cos-meta-md5
的头部,值为该文件的 md5 值,如果带上 --skipmd5 参数则不携带该头部。coscmd list <cospath>
coscmd list doc/
coscmd list -ar
coscmd list examplefolder/ -ar
coscmd list -v
<cospath>
为空默认查询当前存储桶根目录。-a
查询全部文件。-r
递归查询,并且会在末尾返回列出文件的数量和大小之和。-n num
设置查询数量的最大值。coscmd info <cospath>
coscmd info doc/picture.jpg
coscmd download <cospath> <localpath>
coscmd download doc/picture.jpg D:/picture.jpg
coscmd download doc/picture.jpg D:/
coscmd download picture.jpg --versionId MTg0NDUxMzc2OTM4NTExNTg7Tjg D:/
coscmd download -r <cospath> <localpath>
coscmd download -r doc D:/folder/
coscmd download -r / D:/ --ignore "doc/*"
coscmd download -rf / D:/examplefolder/
-f
参数覆盖本地文件。coscmd download -rs / D:/examplefolder
-s
或者 --sync
参数,可以在下载文件夹时跳过本地已存在的相同文件(前提是下载的文件是通过 COSCMD 的 upload 接口上传的,文件携带有 x-cos-meta-md5
头部)。coscmd download -rs --skipmd5 / D:/examplefolder
coscmd download -rs --delete / D:/doc /
coscmd download -rs / D:/examplefolder --ignore *.txt,*.doc
coscmd download -rs / D:/examplefolder --ignore "*.txt"
--ignore
参数可以忽略某一类文件,使用 --include
参数可以过滤某一类文件,支持 shell 通配规则,支持多条规则,用逗号 ,
分隔。当忽略一类后缀时,必须最后要输入 ,
或者加入 ""
。如果 ""
中包含多条逗号分隔的规则,以第一条规则为准。--ignore
过滤特定目录内的所有文件,需要使用绝对路径,并在路径前后加入 ""
。例如 coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*"
。coscmd download -rs / D:/examplefolder --include *.txt,*.doc
coscmd download -rs / D:/examplefolder --include "*.txt"
coscmd signurl <cospath>
coscmd signurl doc/picture.jpg
coscmd signurl doc/picture.jpg -t 100
-t time
设置该 URL 中签名的有效时间(单位为秒), 默认为10000s。coscmd delete <cospath>
coscmd delete doc/exampleobject.txt
coscmd delete doc/exampleobject.txt --versionId MTg0NDUxMzc4ODA3NTgyMTErEWN
coscmd delete -r <cospath>
coscmd delete -r doc
coscmd delete -r folder/doc
coscmd delete -r doc/ --versions
y
确定,使用 -f
参数则可以跳过确认直接删除。coscmd listparts <cospath>
coscmd listparts doc/
coscmd abort
coscmd abort
coscmd copy <sourcepath> <cospath>
coscmd -b examplebucket-1250000000 -r ap-chengdu copy examplebucket-1250000000.ap-chengdu.myqcloud.com/picture.jpg doc/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/photo.jpg -H "{'x-cos-storage-class':'Archive'}"
coscmd copy -r <sourcepath> <cospath>
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
<BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>
。x-cos-metadata-directive
参数,可选值为 Copy 和 Replaced,默认为 Copy。coscmd copy -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
。更多头部请参见 PUT Object - Copy 文档。<sourcepath>
和 <cospath>
不能相同,否则会导致文件被删除。原因在于 move 命令会先复制,再删除,<sourcepath>
路径下的文件最终会被删除。coscmd move <sourcepath> <cospath>
coscmd -b examplebucket-1250000000 -r ap-chengdu move examplebucket-1250000000.ap-chengdu.myqcloud.com/picture.jpg doc/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/picture.jpg doc/folder/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/picture.jpg doc/folder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/data/exampleobject data/examplefolder/exampleobject -H "{'x-cos-storage-class':'Archive'}"
coscmd move -r <sourcepath> <cospath>
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
<BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>
。x-cos-metadata-directive
参数,可选值为 Copy 和 Replaced,默认为 Copy。coscmd move -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
。更多头部请参见 PUT Object - copy 文档。coscmd putobjectacl --grant-<permissions> <UIN> <cospath>
coscmd putobjectacl --grant-read 100000000001 picture.jpg
coscmd getobjectacl picture.jpg
coscmd putbucketversioning <status>
coscmd putbucketversioning Enabled
coscmd putbucketversioning Suspended
coscmd getbucketversioning
coscmd restore <cospath>
coscmd restore -d 3 -t Expedited picture.jpg
coscmd restore -r <cospath>
coscmd restore -r -d 3 -t Expedited examplefolder/
-d <day>
设置临时副本的过期时间,默认值:7。-t <tier>
指定恢复模式,枚举值:Expedited (快速取回模式),Standard (标准取回模式),Bulk(批量取回模式),默认值:Standard。
本页内容是否解决了您的问题?