Wednesday, February 18, 2015

FileZilla sftp/scp fails at connection, but ssh is OK.

FileZilla sftp/scp fails at connection, but ssh is OK.

Status: Connecting to 192.168.6.9...
Status: Connected to 192.168.6.9
Error: Connection timed out
Error: Could not connect to server

sftp and/or scp may fail at connection time if you have shell initialization (.profile, .bashrc, .cshrc, etc) which produces output for non-interactive sessions. This output confuses the sftp/scp client. You can verify if your shell is doing this by executing:

# ssh yourhost /usr/bin/true

If the above command produces any output, then you need to modify your shell initialization.

The reason why this issue occurred was because I have a command that will output a string. The script has been fixed:

######
# start up ssh-agent automatically when a new bash session starts.
# Note: the reason why I added -n "$SSH_TTY" is because without it, sftp and/or scp may fail at connection time if you have shell initialization (.profile, .bashrc, .cshrc, etc) which produces output for non-interactive sessions. This output confuses the sftp/scp client.
# Note: the other way: if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
######
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"

if [[ -z "$SSH_AUTH_SOCK" && -n "$SSH_TTY" && -a "$SSHAGENT" && -x "$SSHAGENT" ]]; then
  eval `$SSHAGENT $SSHAGENTARGS`
  trap "kill $SSH_AGENT_PID" 0
fi

http://www.openssh.com/faq.html#2.9
http://serverfault.com/questions/485487/use-bashrc-without-breaking-sftp
http://blog.killtheradio.net/how-tos/ssh-agent-on-cygwin/

No comments: