I am suddenly unable to connect with sftp.

Posted October 23, 2015 6.6k views

I was happily using sftp to connect to my fedora droplet until yesterday. This morning I am suddenly unable to connect both via terminal and GUI.

I am getting this error.

[Abhinav@abhinav-fed22 ~] $ sftp rot@xxxxxxxxxx
root@xxxxxxxx's password: 
Received message too long 543121247

I have reset the ssh keys, and tried a lot of suggestions here and on google. What is suddenly wrong.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

This is issue is caused when you shell initialization (.profile, .bashrc, .cshrc, etc) which produces output for non-interactive sessions such as sftp.

You have to modify .profile, .bashrc, .cshrc files and make sure it doesn’t output any messages.

  • I added a fortune | cowsay on /etc/bashrc. I didn’t thought it would matter in sftp. I will try after removing it.

    Is it possible to add it for ssh session only?

    Update: It worked. As soon as I commented the line in bashrc, sftp started working again.

    I didn’t think it would matter. What does sftp have to do with my bash shell? Also, is there a way to add that line for ssh and isolate it from sftp ( and other protocols )?

    • You can fix this by simply adding the fortune | cowsay below this line [ -z "$PS1" ] && return.

      [ -z "$PS1" ] && returnchecks if your shell session is running interactively and returns without executing any commands below this line if you are running a non interactively session such as sftp. :)

  • I have no changes to bashrc or profile, but the default Droplet in Ubuntu 14.04 results in the same error, the SFTP connection was closed by server