Copy and Move Files with the SFTP Connector Example - Mule 4
Anypoint Connector for SFTP (SFTP Connector) Copy and Move operations enable you to copy and move files or directories on demand.
While SFTP has a native concept of copying and moving, FTP does not. FTP Connector simulates these operations by downloading file content and writing it to a new location, using concurrent streams that start writing and reading at the same time. Because these operations create significant network overhead, use them wisely. Note that the SFTP Connector Move operation does not impact network overhead.
Configure the Copy Operation in Studio
To add and configure the Copy operation in Studio, follow these steps:
-
In the Mule Palette view, search for
sftp
and select the Copy operation. -
Drag the Copy operation onto the Studio canvas.
-
In the General tab of the operation configuration screen, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.
-
Specify the connection information and click OK.
-
Set the Source path field to the path of the file to copy, for example,
source.txt
. -
In the Target path field, enter the directory path into which to copy the file, for example,
backup
. -
Set the Rename to field to rename the file as part of the operation, for example,
renamed.txt
.
This parameter must be a file name, not a path. If this attribute is not provided, the original file name is used.
The following screenshot shows the Copy operation configuration:
In the XML editor, the <sftp:copy>
configuration looks like this:
<sftp:copy sourcePath="source.txt"
targetPath="backup" overwrite="true|false"
createParentDirectories="true|false"
renameTo="renamed.txt"/>
Configure the Move Operation in Studio
To add and configure the Move operation in Studio, follow these steps:
-
In the Mule Palette view, search for
sftp
and select the Move operation. -
Drag the Move operation onto the Studio canvas.
-
In the General tab of the operation configuration screen, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.
-
Specify the connection information and click OK.
-
Set the Source path field to the path of the file to move, for example,
source.txt
. -
In the Target path field, enter the directory path into which to move the file, for example
backup
. -
Set the Rename to field to rename the file as part of the operation, for example,
renamed.txt
.
This parameter must be a file name, not a path. If this attribute is not provided, the original file name is used.
The following screenshot shows the Move operation configuration:
In the XML editor, the <sftp:move>
configuration looks like this:
<sftp:move sourcePath="source.txt"
targetPath="backup" overwrite="true|false"
createParentDirectories="true|false"
renameTo="renamed.txt"/>