// This module is included in these assemblies:
// as_connecting-to-ftp.adoc

[id='adding-ftp-finish-middle-connection_{context}']
= Uploading files to an FTP or SFTP server

In an integration, you can upload files to an FTP or SFTP server 
in the middle of a flow or to finish a simple integration. To do this, 
add an FTP or SFTP connection to the middle of a flow or as a simple 
integration's finish connection. 

.Prerequisites
* You created an FTP or SFTP connection. 
* You are creating or editing a flow and {prodname} is prompting you
to add to the integration. Or, {prodname} is prompting you to choose a finish connection. 

.Procedure
. On the *Add to Integration* page, click the plus sign where you 
want to add the connection. Skip this step if {prodname} is
prompting you to choose the finish connection. 
. Click the FTP or SFTP connection that you want to use
to upload files. 
. On the *Choose an action* page, select *Upload*. 
. In the *File name expression* field, type an 
link:{LinkCamelDevGuide}/file[Apache Camel File language] expression that specifies the file or files to upload. (Note that you cannot specify a regular expression.)
+
For example, you can filter for all files that have a specific extension from the FTP server. The following example specifies all files with a `.doc` extension:
+
`'${file:onlyname.noext}.doc'`
+
Leave the *File name expression* field blank if you want to upload all files in the FTP directory.

. In the *FTP directory* field, enter the absolute or relative name of a server directory.
If the *File name expression* field contains an expression, 
then the connection stores the specified file in this directory. If the
*File name expression* field is blank, then the connection uploads to
this directory all files that were received from the previous step. 
. In the *If file exists* field, indicate the behavior when you are 
uploading a file that has the same path and name as a file that is on
the server. Accept the default, *Override*, to overwrite
the file that is on the server with the file that you are uploading. 
Or, select one of the following:
** *Append* adds the content in the file being uploaded to the file
that is on the server. 
** *Fail* throws `GenericFileOperationException`. The integration does
not enter an error state. 
** *Ignore* does not upload the file. The integration continues running
under the assumption that everything is okay.
** *Move* renames one of the files. 
** *TryRename* uploads the file with a temporary name and renames the
file to the desired name. This operation does not check for the 
existence of a file with the desired name, which makes the operation
faster on most servers than when existence checks are done. 
. In the *Temporary file prefix while copying* field, specify a string. 
The connection prepends this string to the name of a file while it is
being uploaded. 
This enables the connection to write to a temporary file on the 
server and then rename that temporary file to have the correct name. 
This is useful for reducing locks when uploading very large files.
. In the *Temporary file name while copying* field, specify a string. 
The connection renames a file being uploaded to have this name 
while it is being uploaded.
This enables the connection to write to a temporary file on the 
server and then rename that temporary file to have the correct name. 
This is useful for reducing locks when uploading very large files.

. Click *Next* to specify the action's input type. 

. In the *Select Type* field, if the data type does not need to be known, 
accept *Type specification not required* 
and click *Next*. You do not need to follow the rest of these
instructions. 
+
However, a structured data type is recommended. For example, if you want 
to map the connection input in a data mapper step then you must specify 
the data type. The data mapper cannot display fields for unstructured data.
+
To specify the data type, click in the *Select Type* field and select one of the following as the schema type:
+
* *JSON schema* is a document that describes the structure of JSON data.
The document's media type is `application/schema+json`. 
* *JSON instance* is a document that contains JSON data. The document's 
media type is `application/json`. 
* *XML schema* is a document that describes the structure of XML data.
The document's file extension is `.xsd`.
* *XML instance* is a document that contains XML data. The
document's file extension is `.xml`. 
* *CSV instance* is a document that contains comma-separated value (CSV) data. The document's file extension is `.csv`. 
ifeval::["{location}" == "downstream"]
+
*Note* _Data Mapper support for CSV data is a Technology Preview feature only._
endif::[]

. In the *Definition* input box, paste a definition that conforms to the
schema type you selected. 
For example, if you select *JSON schema* then you would paste the content of
a JSON schema file, which has a media type of `application/schema+json`.

. In the *Data Type Name* field, enter a name that you choose for the
data type. For example, if you are specifying a JSON schema for
vendors then you might specify `*Vendor*` as the data type name. 
+
You will see this data type name when you are creating 
or editing an integration that uses the connection
for which you are specifying this type. {prodname} displays the type name
in the integration visualization and in the data mapper. 

. In the *Data Type Description* field, provide information that helps you
distinguish this type. This description appears in the data mapper when 
you hover over the step that processes this type. 
. Click *Next*. 

.Result
The connection appears in the integration visualization
where you added it. 
