Sometimes, you may be trying to sftp to a server and you will receive the error, "Received message too long", after which, the server will promptly drop your connection.

Although not so obvious, this error is generally due to output from your shell profile without a TTY existing. Unfortunately, this data will get incorrectly parsed by non-interactive session clients (like sftp), causing ill-desired effects.

In scenarios like this, it helps to make the output conditional. For example, in bash, you can edit your .bashrc to test for the existence of a TTY before outputting to the screen by using the following:

if [ -t 0 ]; then
   echo "I'm a TTY"
fi

Now, when you ssh to your machine, the output will display as expected, but sftp (and related services) will connect rather than erring and dropping the connection.