The warning message you're seeing occurs when transferring files in ASCII mode via FTP. This happens when the remote file contains line endings that don't conform to the expected format for ASCII transfers (CRLF for Windows, LF for Unix).
WARNING! 1 bare linefeeds received in ASCII mode
File may not have transferred correctly.
The APC UPS devices typically generate log files with Unix-style line endings (LF only), but when transferred in ASCII mode, the FTP client expects CRLF line endings. The empty last line in your data.txt file is often the culprit triggering this warning.
Option 1: Force Binary Transfer Mode
The simplest solution is to explicitly set binary mode in your FTP script:
ftp -in $ftpip <
Option 2: Filter the Warning Output
If you must stay in ASCII mode, you can filter out the warning:
ftp -in $ftpip 2>&1 | grep -v "WARNING!.*bare linefeeds" <
Option 3: Use Alternative Transfer Methods
Consider using more modern tools that handle line endings better:
# Using curl
curl -u $ftpuser:$ftppassword ftp://$ftpip/data.txt -o data.txt
# Using wget
wget --ftp-user=$ftpuser --ftp-password=$ftppassword ftp://$ftpip/data.txt
For log files and data that doesn't require ASCII translation (like text files between different OS platforms), binary mode is preferable because:
- It preserves the original file exactly
- Avoids any line ending conversion issues
- Eliminates warning messages
For more robust scripts, consider adding these improvements:
#!/bin/bash
ftpip="192.168.0.50"
ftpuser="username"
ftppassword="password"
{
ftp -in $ftpip <&1 | grep -v "^WARNING!"
# Verify file transfer
if [ -s "data.txt" ]; then
echo "Transfer completed successfully"
else
echo "Error: Empty or missing file" >&2
exit 1
fi
While the warning message doesn't necessarily indicate a failed transfer (your data is likely intact), it's understandable you'd want to eliminate it from cron emails. The binary mode solution is the cleanest approach for this specific case of transferring log files from network devices.
When working with FTP transfers on Linux systems, particularly when fetching files from network devices like APC UPS units, you might encounter this warning:
WARNING! 1 bare linefeeds received in ASCII mode
File may not have transferred correctly.
This warning appears when:
- Transferring files in ASCII mode (default for text files)
- The remote file contains line endings that don't match the local system's expectations
- There are "bare" linefeeds (LF without CR) in UNIX-format files
Many APC network management cards generate text files with UNIX-style line endings (LF only), but the FTP server defaults to ASCII mode which expects CRLF for proper text file transfer. The empty last line in your data.txt triggers this warning.
Solution 1: Force Binary Transfer Mode
The simplest fix is to explicitly set binary mode in your FTP script:
ftp -in $ftpip <
This prevents any line ending conversion during transfer.
Solution 2: Post-Processing the File
If you must use ASCII mode, clean the file afterward:
ftp -in $ftpip <
Solution 3: Alternative Transfer Methods
Consider using more modern tools that handle line endings better:
# Using curl
curl -u $ftpuser:$ftppassword ftp://$ftpip/data.txt -o data.txt
# Using lftp
lftp -e "get data.txt; quit" -u $ftpuser,$ftppassword $ftpip
To stop cron from emailing about this warning while still seeing other errors:
ftp -in $ftpip 2>&1 <
Or redirect all output to /dev/null except for errors:
ftp -in $ftpip >/dev/null <