Sends a file to one or more Elastic Compute Service (ECS) instances.

Usage notes

  • The instances to which to send a file must be in the Running (Running) state.
  • Cloud Assistant Agent must be installed on the instances.
  • Only Cloud Assistant Agent versions that are later than the following ones support file sending. If the ClientNeedUpgrade error code is returned, update Cloud Assistant Agent to the latest version.
    • For Linux instances, the version of Cloud Assistant Agent must be later than 1.0.2.569.
    • For Windows instances, the version of Cloud Assistant Agent must be later than 1.0.0.149.
  • The file that you want to send must not exceed 32 KB in size after it is encoded in Base64.
  • The file may fail to be sent due to instance exceptions, network exceptions, or exceptions on Cloud Assistant Agent. Call the DescribeSendFileResults operation or see Check execution results and troubleshoot common issues for troubleshooting.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesSendFile

The operation that you want to perform. Set the value to SendFile.

RegionIdStringYescn-hangzhou

The region ID of the instance to which to send the file. You can call the DescribeRegions operation to query the most recent region list.

ResourceGroupIdStringNorg-bp67acfmxazb4p****

The ID of the resource group. When you specify this parameter, take note of the following items:

  • The ECS instance specified by the InstanceId parameter must belong to this resource group.
  • If you specify this parameter, you can call the DescribeSendFileResults operation to query file sending results in the specified resource group.
NameStringYesfile.txt

The name of the file. The name supports all character sets and can be up to 255 characters in length.

DescriptionStringNoThis is a test file.

The description of the file. The description supports all character sets and can be up to 512 characters in length.

TimeoutLongNo60

The timeout period for the file sending task. Unit: seconds.

  • A timeout error occurs when a file cannot be sent because the process slows down or because a specific module or Cloud Assistant Agent does not exist.
  • If the specified timeout period is less than 10 seconds, the system sets the timeout period to 10 seconds to ensure that the file can be sent to the instances.

Default value: 60.

TargetDirStringYes/home

The destination directory on the instance to which to send the file. If the specified directory does not exist, the system creates the directory on the instance. The value supports all character sets and cannot exceed 255 characters in length.

ContentTypeStringNoPlainText

The content type of the file. Valid values:

  • PlainText: The file content is not encoded.
  • Base64: The file content is Base64-encoded.

Default value: PlainText.

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

The content of the remote file. The content must not exceed 32 KB in size after it is encoded in Base64.

  • If ContentType is set to PlainText, the Content value is in plaintext.
  • If ContentType is set to Base64, the Content value is Base64-encoded.
FileOwnerStringNotest

The owner of the file. This parameter takes effect only for Linux instances. Default value: root. The value can be up to 64 characters in length.

Note If you want to use a non-root user, make sure that the user exists in the instances.
FileGroupStringNotest

The user group of the file. This parameter takes effect only for Linux instances. Default value: root. The user group name can be up to 64 characters in length.

Note If you want to use a non-root user group, make sure that the user group exists in the instances.
FileModeStringNo0644

The permissions on the file. This parameter takes effect only for Linux instances. You can configure this parameter in the same way as you configure the chmod command.

Default value: 0644, which indicates that the owner of the file has the read and write permissions on the file and that the user group of the file and other users have the read-only permissions on the file.

OverwriteBooleanNotrue

Specifies whether to overwrite a file in the destination directory if the file has the same name as the sent file.

  • true: overwrites the file.
  • false: does not overwrite the file.

Default value: false.

InstanceId.NStringYesi-bp185dy2o3o6n****

The ID of instance N to which to send the file. Up to 50 instance IDs can be specified in each request. Valid values of N: 1 to 50.

Tag.N.KeyStringNoTestKey

The key of tag N to add to the file sending task. Valid values of N: 1 to 20. The tag key cannot be an empty string.

If a single tag is specified to query resources, up to 1,000 resources that have this tag added can be displayed in the response. If multiple tags are specified to query resources, up to 1,000 resources that have all these tags added can be displayed in the response. To query more than 1,000 resources that have specified tags, call the ListTagResources operation.

The tag key can be up to 64 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://.

Tag.N.ValueStringNoTestValue

The value of tag N to add to the file sending task. Valid values of N: 1 to 20. The tag value can be an empty string.

The tag value can be up to 128 characters in length and cannot contain http:// or https://.

Response parameters

ParameterTypeExampleDescription
InvokeIdStringf-7d2a745b412b46****

The file sending task ID.

RequestIdString473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The request ID.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=SendFile
&Content='echo hello'
&InstanceId.1=i-bp185dy2o3o6n****
&Name=file.txt
&RegionId=cn-hangzhou
&TargetDir=/home
&<Common request parameters>

Sample success responses

XML format

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

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

JSON format

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

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

Error codes

HTTP status codeError codeError messageDescription
400RegionId.ApiNotSupportedThe api is not supported in this region.This operation cannot be performed in the specified region. Check whether the region ID is valid.
400MissingParam.InstanceIdThe parameter instanceId is missing or empty.InstanceId.N is required.
400MissingParameter.TagKeyYou must specify Tag.N.Key.Tag.N.Key is required.
400Duplicate.TagKeyThe Tag.N.Key contain duplicate key.The specified tag key already exists. Tag keys must be unique.
400InvalidTagKey.MalformedThe specified Tag.n.Key is not valid.Invalid Tag.N.Key value.
400InvalidTagValue.MalformedThe specified Tag.n.Value is not valid.Invalid Tag.N.Value value.
403FileSize.ExceedLimitThe length of file content exceeds limit.The maximum file content length is exceeded.
403FileName.ExceedLimitThe length of file name exceeds limit.The maximum file name length is exceeded.
403FileDesc.ExceedLimitThe length of file description exceeds limit.The maximum file description length is exceeded.
403FileTargetDir.InvalidThe target directory of file is invalid.Invalid TargetDir value.
403InstanceIds.ExceedLimitThe number of instance IDs exceeds the upper limit.The maximum number of instance IDs is exceeded.
403FileMode.InvalidThe mode of file is invalid.Invalid FileMode value.
403FileContent.DecodeErrorThe Content can not be base64 decoded.The file content cannot be decoded in Base64.
403FileContentType.InvalidThe ContentType of file is invalid.Invalid ContentType value.
403Operation.ForbiddenThe operation is not permitted.The operation is not supported.
404InvalidInstance.NotFoundThe specified instances not found.The specified instances are not found.
404InvalidResourceGroup.NotFoundThe ResourceGroup provided does not exist in our records.The resource group ID is not found.
500InternalError.DispatchAn error occurred when you dispatched the request.An error occurred when the request was being sent. Try again later.

For a list of error codes, see Service error codes.