调用SendFile向一台或多台ECS实例下发远程文件。

接口说明

  • 目标ECS实例的状态必须为运行中(Running)。
  • 目标ECS实例必须预先安装云助手Agent
  • 云助手Agent版本需要高于以下对应的版本才能支持下发文件。如果结果返回ClientNeedUpgrade错误码,请将客户端更新至最新版本。
    • Linux:1.0.2.569
    • Windows:1.0.0.149
  • 文件内容在进行Base64编码后,大小不能超过32 KB。
  • 文件下发可能会因为目标ECS实例的状态异常、网络异常或云助手Agent异常而出现失败的情况。请调用DescribeSendFileResults,或参考执行失败常见错误及修复建议进行问题排查。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String SendFile

系统规定参数。取值:SendFile

RegionId String cn-hangzhou

目标ECS实例所在的地域ID。您可以调用DescribeRegions查看最新的阿里云地域列表。

ResourceGroupId String rg-bp67acfmxazb4p****

文件下发的资源组ID,当指定该参数时:

  • InstanceId对应的ECS实例必须属于该资源组。
  • 支持通过指定该参数筛选出对应的文件下发结果(通过调用DescribeSendFileResults)。
Name String file.txt

文件名称。支持全字符集,长度不得超过255个字符。

Description String This is a test file.

描述信息。支持全字符集,长度不得超过512个字符。

Timeout Long 60

下发文件的超时时间。单位:秒。

  • 当因为进程原因、缺失模块、缺失云助手Agent等原因无法下发文件时,会出现超时现象。
  • 当设置的超时时间小于10秒时,为确保下发成功,系统会将超时时间自动设置为10秒。

默认值为60。

TargetDir String /home

文件下发目标ECS实例中的目录。如不存在则会自动创建。长度不得超过255个字符。

ContentType String PlainText

文件内容类型。

  • PlainText:普通文本。
  • Base64:Base64编码。

默认值为PlainText。

Content String #!/bin/bash echo "Current User is :" echo $(ps | grep "$$" | awk '{print $2}') -------- oss://bucketName/objectName

文件内容。文件内容在Base64编码后,大小不能超过32 KB。

  • ContentType参数为PlainText时,该字段为明文格式的普通文本。
  • ContentType参数为Base64时,该字段为Base64编码的文本。
FileOwner String test

文件的用户。只对Linux实例生效,默认为root。长度不得超过64个字符。

说明 使用其他用户时,请确保实例中存在该用户。
FileGroup String test

文件的用户组。只对Linux实例生效,默认为root。长度不得超过64个字符。

说明 使用其他用户组时,请确保实例中存在该用户组。
FileMode String 0644

文件的权限。只对Linux实例生效,设置方式与chmod命令相同。

默认值为0644,表示用户具有读写权限,用户组和其它用户具有只读权限。

Overwrite Boolean true

如果同名文件在目标目录已存在,是否覆盖文件。

  • true:覆盖。
  • false:不覆盖。

默认值为false。

InstanceId.N String i-bp185dy2o3o6n****

需要执行命令的ECS实例列表。最多能指定50台ECS实例ID。N的取值范围为1~50。

Tag.N.Key String TestKey

文件下发的标签键。N的取值范围为1~20。一旦传入该值,则不允许为空字符串。

使用一个标签过滤资源,查询到该标签下的资源数量不能超过1000个。使用多个标签过滤资源,查询到同时绑定了多个标签的资源数量不能超过1000个。如果资源数量超过1000个,您需要使用ListTagResources接口进行查询。

最多支持64个字符,不能以aliyunacs:开头,不能包含http://https://

Tag.N.Value String TestValue

文件下发的标签值。N的取值范围为1~20。该值可以为空字符串。

最多支持128个字符,不能包含http://https://

返回数据

名称 类型 示例值 描述
InvokeId String f-7d2a745b412b46****

命令执行ID。

RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

请求ID。

示例

请求示例

https://ecs.aliyuncs.com/?Action=SendFile
&Content='echo hello'
&InstanceId.1=i-bp185dy2o3o6n****
&Name=file.txt
&RegionId=cn-hangzhou
&TargetDir=/home
&<公共请求参数>

正常返回示例

XML格式

HTTP/1.1 200 OK
Content-Type:application/xml

<SendFileResponse>
        <RequestId>E69EF3CC-94CD-42E7-8926-F133B86387C0</RequestId>
        <InvokeId>f-7d2a745b412b46****</InvokeId>
</SendFileResponse>

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "E69EF3CC-94CD-42E7-8926-F133B86387C0",
  "InvokeId" : "f-7d2a745b412b46****"
}

错误码

HttpCode 错误码 错误信息 描述
400 RegionId.ApiNotSupported The api is not supported in this region. 指定地域下不支持调用 API。请检查 RegionId 参数取值是否正确。
400 MissingParam.InstanceId The parameter instanceId is missing or empty. 实例ID为空。
400 MissingParameter.TagKey You must specify Tag.N.Key. 请指定标签键。
400 Duplicate.TagKey The Tag.N.Key contain duplicate key. 标签中存在重复的键,请保持键的唯一性。
400 InvalidTagKey.Malformed The specified Tag.n.Key is not valid. 指定的标签键参数有误。
400 InvalidTagValue.Malformed The specified Tag.n.Value is not valid. 指定的标签值参数有误。
400 FileTargetDir.Invalid The target directory of file is invalid. 目标路径TargetDir参数无效。
400 FileMode.Invalid The mode of file is invalid. 文件权限FileMode参数无效。
400 FileContent.DecodeError The Content can not be base64 decoded. 文件内容Base64解码错误。
400 FileContentType.Invalid The ContentType of file is invalid. 文件内容类型ContentType参数无效。
400 InvalidParameter.FileOwner The specified parameter FileOwner is not valid. 指定的参数FileOwner不合法。
400 InvalidParameter.FileGroup The specified parameter FileGroup is not valid. 指定的参数FileGroup不合法。
403 FileSize.ExceedLimit The length of file content exceeds limit. 文件内容长度超过上限。
403 FileName.ExceedLimit The length of file name exceeds limit. 文件名称长度超过上限。
403 FileDesc.ExceedLimit The length of file description exceeds limit. 文件描述长度超过上限。
403 InstanceIds.ExceedLimit The number of instance IDs exceeds the upper limit. 目标实例数量超过上限。
403 Operation.Forbidden The operation is not permitted. 该操作是不被允许的。
404 InvalidInstance.NotFound The specified instances not found. 指定的实例ID不存在。
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. 资源组并不在记录中。
500 InternalError.Dispatch An error occurred when you dispatched the request. 发送请求时发生错误,请稍后重试。

访问错误中心查看更多错误码。