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

Description

  • The instances to which to send a file must be in the Running (Running) state.
  • The Cloud Assistant client must be installed on the instances. For information about how to install the Cloud Assistant client, see InstallCloudAssistant.
  • Only the Cloud Assistant client versions that are later than the following ones support file sending. If the ClientNeedUpgrade error code is returned, you must upgrade the Cloud Assistant client to the latest version. For more information, see Update or disable updates for the Cloud Assistant client.
    • For Linux instances, the version of the Cloud Assistant client must be later than 1.0.2.569.
    • For Windows instances, the version of the Cloud Assistant client must be later than 1.0.0.149.
  • The file to be sent must not exceed 32 KB in size after it is encoded in Base64.
  • The file may fail to be sent due to exceptions on the instances, network, or the Cloud Assistance client. Call the DescribeSendFileResults operation to troubleshoot the issues.

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

Parameter Type Required Example Description
Action String Yes SendFile

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

RegionId String Yes cn-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.

Name String Yes file.txt

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

Description String No This is a test file.

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

Timeout Long No 60

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

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

Default value: 60.

TargetDir String Yes /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.

ContentType String No PlainText

The content type of the file. Valid values:

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

Default value: PlainText.

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

The content of the 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.
FileOwner String No root

The owner of the file. This parameter takes effect only on Linux instances. Default value: root.

FileGroup String No root

The user group of the file. This parameter takes effect only on Linux instances. Default value: root.

FileMode String No 0644

The permissions on the file. This parameter takes effect only on 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 only the read permissions on the file.

Overwrite Boolean No true

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.N String Yes i-bp185dy2o3o6n****

The ID of instance N to which to send the file. A maximum of 50 instance IDs can be specified. Valid values of N: 1 to 50.

Response parameters

Parameter Type Example Description
InvokeId String f-7d2a745b412b46****

The ID of the execution.

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

The ID of the request.

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

HttpCode Error code Error message Description
400 RegionId.ApiNotSupported The api is not supported in this region. The error message returned because the API operation cannot be called in the specified region. Check whether the RegionId parameter is valid.
403 FileSize.ExceedLimit The length of file content exceeds limit. The error message returned because the maximum length of the file content has been reached.
403 FileName.ExceedLimit The length of file name exceeds limit. The error message returned because the maximum length of the file name has been reached.
403 FileDesc.ExceedLimit The length of file description exceeds limit. The error message returned because the maximum length of the file description has been reached.
403 FileTargetDir.Invalid The target directory of file is invalid. The error message returned because the specified TargetDir parameter is invalid.
403 InstanceIds.ExceedLimit The number of instance IDs exceeds the upper limit. The error message returned because the maximum number of specified instance IDs has been reached.
403 FileMode.Invalid The mode of file is invalid. The error message returned because the specified FileMode parameter is invalid.
403 FileContent.DecodeError The Content can not be base64 decoded. The error message returned because the file content cannot be decoded in Base64.
403 FileContentType.Invalid The ContentType of file is invalid. The error message returned because the specified ContentType parameter is invalid.
403 Operation.Forbidden The operation is not permitted. The error message returned because the operation is not supported.
404 InvalidInstance.NotFound The specified instances not found. The error message returned because the specified InstanceId parameter does not exist.
500 InternalError.Dispatch An error occurred when you dispatched the request. The error message returned because an error occurred when the request was being sent. Try again later.

For a list of error codes, visit the API Error Center.