Contact Us 1-800-596-4880

Copy and Move Files - Mule 4

Anypoint Connector for File (File Connector) provides the Copy and Move operations that enable you to copy or move files or directories on demand.

  • Source path
    The directory path name or file name to copy or move. If a file or directory already exists and the Overwrite field is set to false, the connector throws the message FILE:FILE_ALREADY_EXISTS.

  • Target path
    The directory path name into which to copy or move the file. If a target path doesn’t exist, and neither does its parent, the connector attempts to create the path depending on the value of the Create parent directories argument. If Create parent directories is false, then FILE:ILLEGAL_PATH occurs.

  • Rename to
    Renames the file as part of the operation. Set this field with a file name instead of a path. The connector retains the original file name if you do not configure this field.

Configure the Copy Operation in Studio

  1. In the Mule Palette view, search for file and select the Copy operation.

  2. Drag the Copy operation onto the Studio canvas.

  3. 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.

  4. Specify the connection information and click OK.

  5. Set Source path to the path of the file to copy, for example, Documents/source-folder/file.txt.

  6. Set Target path to the directory path into which to copy the file, for example, Documents/target-folder.

  7. Set Rename to to rename the file as part of the operation, for example, renamed.txt.
    This field must be a filename, not a path. If this attribute is not provided, the original filename is used.

Copy operation configuration in Studio

In the Configuration XML editor, the <file:copy> configuration looks like this:

<flow name="file-connector-testFlow" >
		<http:listener config-ref="HTTP_Listener_config" path="/copy"/>
		<file:copy doc:name="Copy" sourcePath="Documents/source-folder/file.txt" targetPath="Documents/target-folder" config-ref="File_Config" overwrite="true" renameTo="renamed.txt"/>
	</flow>

Configure the Move Operation in Studio

To add and configure the Move operation in Studio, follow these steps:

  1. In the Mule Palette view, search for ftp and select the Move operation.

  2. Drag the Move operation onto the Studio canvas.

  3. 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.

  4. Specify the connection information and click OK.

  5. Set Source path to the path of the file to move, for example, source.txt.

  6. Set Target path to the directory path into which to move the file, for example, backup.

  7. Set Rename to to rename the file as part of the operation, for example, renamed.txt.
    This field must be a filename, not a path. If this attribute is not provided, the original filename is used.

Move operation configuration in Studio

In the Configuration XML editor, the <file:move> configuration looks like this:

<flow name="file-connector-testFlow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/copy"/>
		<file:move doc:name="Move" config-ref="File_Config" sourcePath="source.txt" targetPath="backup" renameTo="renamed.txt"/>
	</flow>
View on GitHub