This article shows how to make a FlexEdge™ DA50A or DA70A send its data log files to an FTP server automatically, using the Crimson 3.2 Sync Manager. It also shows how to let an FTP client read files from the FlexEdge's own FTP server instead.
The Sync Manager is Crimson's FTP client. Despite its name, it isn't limited to log files: the FtpPutFile() and FtpGetFile() functions in the Crimson 3.2 Reference Guide use the same client for transfers you start from a program.
Preparation
-
FlexEdge DA50A or DA70A:
- Running Crimson 3.2 firmware, reachable from your PC for the database download.
- Licensed for software Group 3 or higher. The Sync Manager and the Data Logger are not available in a Group 1 or Group 2 database.
-
Crimson 3.2:
- Installed on your PC, with the FlexEdge's database open.
-
An FTP server:
- Reachable from the FlexEdge: its IP address or host name, its port (usually 21), and whether it uses plain FTP, explicit TLS (FTPS) or implicit TLS.
- A user name and password for the FlexEdge, with permission to create folders and write files.
Example Setup
The steps below use these example values. Replace them with your own.
- FTP server: 192.168.1.50, port 21, plain FTP.
- FTP account: flexedge01.
- Folder on the server for this FlexEdge: /FlexEdge01.
- How often to send: every hour.
Part 1: Send Data Logs to an FTP Server (Sync Manager)
Step 1: Create a Data Log
The Sync Manager sends the files of the data logs in the database. Skip this step if the database already logs the data you want.
- Click the Data Logger category, then click the New button at the top left of the Navigation Pane to create a log.
- On the log's Setup tab, set the update rate and file size you need, and note the Storage Device. On the FlexEdge, the default is Internal Memory.
- On the Contents tab, drag the tags to log from the Resource Pane.
Note: The FlexEdge writes each log's files to the folder set by its Path Name, under a LOGS folder on the storage device (for example LOGS/Log1 for a log named Log1). A file holding an hour or more of data is named YYMMDDhh.CSV; a shorter one is named MMDDhhmm.CSV.
Step 2: Configure the Sync Manager
- Click the Communications category and navigate to Services > Sync Manager.
- Under Settings, set the following:
- Enable Sync Manager: Yes.
- Enable Log File Sync: Yes.
- Storage Device: the same location as your data logs. On the FlexEdge, Default is internal memory, Thumb Drive is a USB memory stick and Extended is the memory card.
- Under FTP Client, set the following:
- Server IP Address: 192.168.1.50. You can also enter a host name, or select a tag that holds the address.
- Port Number: 21.
- Transport Protocol: TCP for plain FTP. See Step 3 for TLS.
- Logon Username: flexedge01. Leave it empty to log in as anonymous.
- Logon Password: the account's password.
- Data Connection: PASV Mode. In this mode the FlexEdge opens every data connection, which works through firewalls, NAT and cellular connections. Use Standard only if the server needs it.
- LIST Mode: Per Directory. Choose Per File on a metered cellular plan when the server folder holds many files, to send less data.
- Keep Alive: 10 secs (the default). The connection stays open this long in case more files follow; 0 closes it after each transfer.
- Under Log Synchronization, set the following:
- Base Directory: /FlexEdge01. This is a folder on the FTP server, as the FTP client sees it. Give each FlexEdge that sends to the same server its own folder.
- Sync Hours: 1 and Sync Minutes: 0. Together they set how often the files are sent.
- Sync Offset: 0. When several devices send to one server at the same interval, give each a different offset in minutes, smaller than the interval, so they don't all connect at once.
Note: On the server, the FlexEdge keeps the same layout under the Base Directory: <Base Directory>/LOGS/<log folder>/<file>, for example /FlexEdge01/LOGS/Log1/12011030.CSV. It creates any of these folders that are missing, including the Base Directory itself.
At each sync the FlexEdge lists the log's folder on the server and sends every file that is missing there or whose size differs from its own copy. A finished file is therefore sent once, while the file that is still being written is sent again at each sync until it is complete.
Step 3 (Optional): Encrypt the Connection with TLS
If the FTP server supports FTPS, set Transport Protocol to match it:
- TLS Explicit: the FlexEdge connects without encryption, usually to port 21, and switches to TLS with the AUTH command before logging in. Most current FTPS servers use this.
- TLS Implicit: the connection is encrypted from the start. Older servers use this, usually on port 990, so also set Port Number to 990.
With either TLS option Crimson sets Data Connection to PASV Mode and greys it out, and the file transfers are encrypted as well as the logon.
No certificate needs to be installed on the FlexEdge: the Sync Manager has no certificate settings and accepts the server's certificate, including a self-signed one. This also means the FlexEdge does not check that it is talking to the right server. TLS keeps the password and the files private on the way, but over the internet it is still best to reach the server through a VPN.
Step 4: Download and Check the Transfer
- Save the database and download it to the FlexEdge.
- The FlexEdge connects to the server shortly after the database starts, then at each sync interval. Check the Base Directory on the FTP server for the log files.
If no files arrive:
- Check the FTP server's own log for a connection or login attempt from the FlexEdge's IP address. No attempt means the FlexEdge can't reach the server: check the address, port and routing, and any firewall between them.
- A failed login means a wrong user name or password. Both are usually case sensitive.
- A login that is followed by failed transfers usually points to the data connection: try the other Data Connection setting, and make sure the server's passive port range is open in its firewall. After a failed attempt the FlexEdge tries again about every 10 to 15 seconds.
- With LIST Mode Per Directory, the FlexEdge lists the folder with a wildcard (for example LIST /FlexEdge01/LOGS/Log1/*). A server that doesn't accept the wildcard answers with an error, and the FlexEdge keeps retrying without sending any file.
- If the same files arrive again at every sync, the server is probably changing them. The FlexEdge sends files in ASCII mode with Windows line endings (CR LF); a server that converts these to Unix line endings (LF) stores a smaller file, so the sizes never match and every file is sent again. Set the server to store ASCII uploads unchanged.
- For more detail, set Record Log File to Yes to keep a log of every FTP exchange on the FlexEdge, or set Debug Output to Enabled to print diagnostics to the debug console. Turn both off again afterwards, as they slow the device slightly. With the Sync Manager's Storage Device set to Default, the record log is FTP.LOG in the root of the FlexEdge's internal memory (the top folder of its FTP server). It contains the FTP password in plain text, so delete it once you have finished.
Part 2 (Optional): Read Files from the FlexEdge's FTP Server
Instead of the FlexEdge sending files, an FTP client such as FileZilla can connect to the FlexEdge and download them. In Crimson 3.2 the FTP server runs all the time, independently of the database, and uses the accounts in the User Configuration. It also gives access to USB memory sticks and memory cards in the device.
Step 1: Enable the FTP Server
- Click the Device Configuration category and navigate to System Configuration > Services > FTP Server. You can make the same settings in the FlexEdge's system web server.
- Set the following:
- Operation: Enabled.
- Anonymous Access: Disabled (the default), unless anonymous users really need access.
- TLS Support: Enabled (the default) allows both encrypted and unencrypted connections; Required refuses clients that don't use TLS. The FTP server identifies itself with the default device certificate from Network > Identity.
- Port Number: 21 (the default).
Step 2: Give the User FTP Rights
- Open the User Configuration in the FlexEdge's system web server (the menu under the current user name) or in Device Configuration in Crimson.
- For the user who will log in over FTP, check FTP Rights. With Based on Level, users above Read Only get read-write access and Read Only users get read-only access.
Note: By default, Crimson doesn't include the User Configuration when it downloads a database, so that the users already on the device are kept. Manage users in the system web server, or turn that option on before you download.
Step 3: Connect with an FTP Client
- Connect your FTP client to the FlexEdge's IP address on port 21, with the user's name and password. Choose explicit FTP over TLS if the client offers it.
- Find the data logs in the LOGS folder. The top folder is the FlexEdge's internal memory, so logs kept there are in /LOGS. A USB memory stick appears as DRIVE-D and a memory card as DRIVE-E. Both are always listed, but opening one fails with "Directory cannot be found" when nothing is inserted.
Note: FTP isn't in the predefined Untrusted Traffic list of the FlexEdge firewall. To reach the FTP server through an interface that isn't trusted (for example a WAN connection), add a custom entry under Network > Firewall > Untrusted Traffic for TCP port 21. For passive data connections the FTP server picks a random port between 32768 and 60999. With plain FTP, the firewall follows the FTP commands and lets those data connections in, so port 21 is enough. Don't expose an FTP server to the internet; use a VPN.
When using FTP over TLS (FTPS) through an Untrusted interface, you may also need to explicitly allow the passive FTP data port range in the Untrusted Traffic configuration. Because the FTP control channel is encrypted, the firewall's FTP connection-tracking helper may be unable to dynamically permit the associated data connections.
Restrict access to authorized client IP addresses using a White List wherever possible.
Part 3: Frequently Asked Questions (FAQ)
Question: Is there an older article about the Sync Manager?
Answer: Crimson: FTP SyncManager (TNOI27) covers the same service in Crimson 3.0 and 3.1. This article covers Crimson 3.2 and the FlexEdge.
Question: Can I send a file at a time I choose, rather than on the sync interval?
Answer: Yes. With Enable Sync Manager set to Yes, a program can call FtpPutFile() or FtpGetFile() to transfer a file with the same FTP client settings. Automatic log sync can stay off. See the Crimson 3.2 Reference Guide for these functions.
Question: Can I get the logs without an FTP server?
Answer: Yes. The Crimson web server can serve the log files, the FlexEdge can copy them to a USB memory stick, and SQL Sync can send logged data to a Microsoft SQL Server database. See also Crimson 3.1: Using Websync2 to Retrieve CSV Files.
Disclaimer
It is the customer's responsibility to review the advice provided herein and its applicability to the system. Red Lion makes no representation about specific knowledge of the customer's system or the specific performance of the system. Red Lion is not responsible for any damage to equipment or connected systems. The use of this document is at your own risk. Red Lion standard product warranty applies.
HMS Technical Support
If you have any questions or trouble contact HMS Technical Support by clicking here.