Exchanging Files with the FTP Adapter
- Neuron ESB
- Samples and Walkthroughs
- Adapters (Samples)
- Exchanging Files with the FTP Adapter
Neuron ESB can send and receive files over FTP. The adapter provides several options for connecting to FTP servers and receiving and sending files.
This sample consists of four adapter endpoints:
- FileReceiveEndpoint – configured to receive files from a file location and publish then to the ESB. These files are routed to the FtpSendEndpoint.
- FtpSendEndpoint – configured to send files to an FTP Server. This endpoint’s subscriber is configured to execute the Set FTP Filename Process that sets the filename of the outgoing file.
- FtpReceiveEndpoint – configured to receive files from an FTP Server. These files are routed to the FileSendEndpoint
- FileSendEndpoint – configured to send files to a file location. This endpoint’s subscriber is configured to execute the Set File Filename Process that sets the filename of the outgoing file.
The Set FTP Filename process contains a single code step that sets the only outbound dynamic property supported by the FTP adapter:
context.Data.SetProperty("ftp", "Filename", "log.txt");
The Set File Filename process accesses a number of inbound dynamic properties and uses the values to set the filename of the file written to the file system:
string server = String.Empty; string port = String.Empty; string username = String.Empty; string folder = String.Empty; string filename = String.Empty; // Get the FTP Server if (!context.Data.TryGetProperty("ftp", "Server", ref server)) server = "localhost"; // Get the FTP Port if (!context.Data.TryGetProperty("ftp", "Port", ref port)) server = "21"; // Get the FTP Username if (!context.Data.TryGetProperty("ftp", "Username", ref username)) username = "Anonymous"; // Get the FTP Folder the message was read from if (!context.Data.TryGetProperty("ftp", "Folder", ref folder)) folder = "Home"; // Get the FTP Filename if (!context.Data.TryGetProperty("ftp", "Filename", ref filename)) filename = "FilenameNotFound.txt"; // Set the path the file adapter will write the file to based on FTP message properties context.Data.SetProperty("file_out", "Path", "C:\\FileOut\\" + server + "\\" + port + "\\" + username + "\\" + folder + "\\"); // Set the filename the file adapter will use based on the metadata properties of the incoming FTP file. context.Data.SetProperty("file_out", "Name", filename);
The FtpReceiveEndpoint is configured as follows:
The FtpSendEndpoint is configured as follows:
Running the Sample
- To run this sample you must have access to an FTP server.
Open the Sample
To open this sample, see the topic Using the Neuron Samples and select the FTP Adapter sample.
Configure Adapter Endpoints
FTP Adapter Endpoints
You’ll need to verify the FTP Adapter endpoint settings.
- In the Neuron ESB Explorer, navigate to Connections->Endpoints->Adapter Endpoints.
- Select the adapter endpoint FtpReceiveEndpoint, and verify the Server Name, Port, and Username/Password fields are valid for your FTP server.
- After modifying the adapter endpoint properties, click the Apply button.
- Repeat steps 1-3 for the FtpSendEndpoint endpoint.
Verify the Folder Path setting for both the FileReceiveEndpoint and FileSendEndpoint are configured correctly. The FileReceiveAdapter endpoint reads files from the folder C:\FileIn, and the FileSendEndpoint endpoint writes files to the folder C:\FileOut. If you would like the file adapter endpoint to save messages to a different location, modify the file adapter endpoint setting Folder Path.
Run the Sample
- This sample polls for files in C:\FileIn and sends them to the FTP server configured in the endpoint FtpSendEndpoint. It also polls for files in the folder on the FTP server configured in the endpoint FtpReceiveEndpoint and sends them to the folder C:\FileOut.
- To test sending to an FTP server, copy a file to C:\FileIn. The file will be read and sent to the configured FTP server.
- To test receiving from an FTP server, copy a file to the FTP server that Neuron is polling from. The file will be read and sent to C:\FileOut.