When you are trying to SFTP from client to server, and you are getting the error message: “Received too large () SFTP packet,” Max supported packet size is ( ),” or “Bad packet length.” In a nutshell, this means that your SFTP client received unknown or bad data from the server.
Generally, this error is due to the shell startup files scripts such as .bashrc or .profile on the SFTP server, producing an output (warning, welcome, debug, etc.) to be read by a human. Since SFTP uses the same SSH process, your SFTP client tries to parse this output as if it was a standard SFTP message and thus the error.
For more details on this error message, its diagnosis, troubleshoot, and solution, keep reading.
1. The Received Message Too Long Error
This error message appears when trying to SFTP to a server.
In Windows: “Received too large SFTP package.”
Received too large (1298752370 B) SFTP package. Max supported package size
is 1024000 B.
The error is typically caused by message printed from startup script (like
.profile). The message may start with “Micr”.
Cannot initialize SFTP protocol. Is the host running a SFTP server?
In Linux or macOS machines: “Received message too long”
# sftp firstname.lastname@example.org
Connecting to acme.com…
Received message too long 1298752370
The “SFTP received message too long (decimal number)” error is caused by the default shell startup (or initialization) file, such as .bashrc, .bash_profile, /etc/profile, or .cshrc, on the remote system (the SFTP server), which is running a command attempting to write text into the terminal. As a result, the SSH session has information being transmitted by a program at either the system or the per-user shell startup files, interfering with the normal SFTP or SCP protocol.
These startup files output text messages on login intended for humans, such as “Hello, today is …” conflict with SFTP. In other words, the SSH shell session might be trying to say “hi,” (because you initiated it with SFTP), but SFTP doesn’t understand “hi.”
Reasons for the SFTP “received message too long” error:
- The sshd, SSH Daemon, or OpenSSH server processes use the user’s shell when initializing a particular script. Running commands from the shell startup has several advantages, for example, triggering a user’s preferred setup or restricting a remote user from issuing other commands, but could conflict with SFTP or SCP.
- A script, command, or program might be causing the issue. For example, an “echo” command or a program was running from the startup file outputs text to the screen. For example, debugging “echo” statements or welcome messages that pop up after a successful login.
The idea is to find this command that is interfering with the SFTP protocol messaging. As said before, this command or script is initiated by the bash startup file. This starter bash file needs to be quiet to not interfere with the SFTP (or SCP2) protocol. We quiet it down by commenting or isolating the SFTP session.
If this error is happening to all the users connecting to the SFTP server, locate the system-wide startup files for the login shell, which generally can be found in /etc. But if the “Received message too long” error is only happening to one user, verify their personal shell files located in their home directory.
SSH into the same server that you are trying to SFTP
SSH works but SFTP and SCP2 fail. If you are successful in SSH and see a welcome message, you might need to go into the shell startup file (~/.bashrc) and comment on the respective command line. But if you don’t get a welcome message, then you might need to look somewhere else.
a. Probing the output of the SSH
According to a solution from ServerFault, you can use the command:
- ssh “yourhost” /usr/bin/true, to probe the output of your ssh.
- If you get an outcome, then you’ll need to modify the shell startup.
In addition, you can also try:
- ssh user@remote ‘echo hello'.
- If you get an output other than the “hello,” then probably that specific output prevents the SFTP protocol from functioning correctly.
b. Locate noisy commands in .bashrc or .bash_profile
Remove debugging echo statements in your .bashrc and .bash_profile etc. Errors or outputs from these files might be interfering with SFTP/SCP. To find these, start from the message output.
- The decimal numeric value like “1298752370” that you found on the error message represents the actual ASCII string returned by the SFTP server. Therefore, translating the (decimal number) shown in the error display can help you locate the command.
- Use a calculator to translate from decimal to hexadecimal to ASCII. For example, 1298752370 (decimal) > 4D696372 (Hex) > Micr (ASCII). Or, 1416586337 (decimal) > 546F6461 (Hex) > “Toda” (ASCII).
- Open the startup shell files (.bashrc) with the vi or nano editor.
c. Comment out the command, discard the output or return early
You found the code “polluting” the standard stream between the SFTP client and the SFTP server. This code should be designed to only produce output on interactive logins.
- Go through the shell’s startup commands, and try to locate the command that is producing the output (noise). Look for a command that uses the same string, for example, echo “Micr … ”. or echo “Toda…”.
- The idea is to remove, change, or comment on the commands to avoid running during non-interactive SSH sessions.
- Add the line “/dev/null 2>&1” to discard the standard output with
If you don’t want to remove the command from the bash startup file, you could configure the shell to exit the script for SFTP early. So rather than sourcing the entire file, the suggested following commands makes an early exit. Note that the shell syntax may vary.
- To do that, put the following line on top of the startup file: if(!$?prompt)exit
- A similar approach, according to Scott Stensland, from UNIX& Linux Stack Exchange, is to put the following line on top of the startup file (~/.bashrc) on the username of id on the remote machine:
- # If not running interactively, don't do anything and return early
- [[ $- == *i* ]] || return
d. Set the SSH server to use internal-sftp for the SFTP sessions
Furthermore, you may want to use your personal shell startup file still while allowing SFTP also to go through. In other words, to launch the SFTP session without the user shell. For that, you’ll need to change the SFTP subsystem on the SFTP internal level of your server.
- Use root access for this solution.
- Locate and open the /etc/ssh/sshd_config file. Use “nano” or “vi” to edit the file.
- Locate and add comment (#) to the line: Subsystem sftp /usr/lib/openssh/sftp-server
- Add the following line: Subsystem sftp internal-sftp
- Perform a “sudo service sshd restart” and “sudo service vsftpd restart.”
4. Try Alternatives to OpenSSH
Using a combination of OpenSSH and commercial tools may also be a reason for the problem. For example, if you are using OpenSSH as a server and clients are using other commercial tools.
Try OpenSSH Server and Client or alternatives to OpenSSH
OpenSSH is an open-source collection of secure networking utilities based on the secure shell protocol. It is widely used as the leading SSH solution in Linux distributions, mainly because it is free and includes SFTP, SCP, and SThus, SH. OpenSSH is the best solution if you feel confident working through commands. However, it does not come with a Graphical User Interface, and it is not friendly for beginners, as it requires advanced experience in syntax and SFTP.
A great alternative to OpenSSH, SolarWinds Serv-U MFT Server is a highly versatile and secure FTP server tool. It supports SFTP, FTPS, and FTP. You can use Serv-U MFT to connect multiple FTP clients and servers simultaneously and perform multiple concurrent transfers at once. In addition, the server also allows drag-and-drop file transfers and automatic folder synchronization. The advantage is that the graphical user is easy to install and use.
Below is a screenshot of the Serv-U Web Client.
b. FileZilla FileSharing Solution
FileZilla Solution is a multiplatform client/server FTP tool that works in Windows, Linux, and macOS. It supports FTP, SFTP, and FTPS file transfers. FileZilla is one of the most popular free and open-source file management tools that offer advanced functionalities. This tool is also easy to set up and use.
Download FileZilla. It provides both the server and the client.
In this troubleshooting guide to solve the SFTP received message too long, we went deep into the main reason for the problem. We also provided ways to solve it and potential SFTP client/server software alternatives, including SolarWinds Serv-U or FileZilla.
We hope you managed to fix your received message too long problem. Please leave your comments, questions, and suggestions below.