sftp packet length error with loaded .bashrc

0

I regularly use WinSCP to tranfer a few files to my personal server. However I recently experienced the infamous "bad packet length" error due to one of my echo statements residing inside the .bashrc file. Therefore with respect to this: sftp corruption error I would like to ask the following:

Why did the system complained for an echo statement (or whatever is causing the error) residing within my .bashrc file and not my .bash_profile instead?

..if the sftp is some sort of subprocess spawned by the ssh server as the above link suggests, shouldn't it first parse the .bash_profile file and complain about its own echo statements?

Thanks in advance

kstratis

Posted 2012-07-13T14:51:16.803

Reputation: 159

Answers

2

I use the following line (two with comment) at the top of my .bashrc, it simply aborts if it isn't an interactive shell:

# if we're not an interactive shell, do nothing
[ -z "$PS1" ] && return

I suppose if you want the long form:

# if we're not an interactive shell, do nothing
if [ -z "$PS1" ]; then
    return
fi

This mitigates the need for a .bashrc_profile file, since the .bashrc changes how it responds based on how it was invoked.

lornix

Posted 2012-07-13T14:51:16.803

Reputation: 9 633

1

.bash_profile executes for login shells. .bashrc executes for interactive shells. Apparently, WinSCP must be creating a non-login interactive shell on the remote machine. Details can be found in the INVOCATION section of the Bash man page.

Fran

Posted 2012-07-13T14:51:16.803

Reputation: 4 774

Shouldn't WinSCP create a non-login non-interactive shell instead? I can't see how a session is considered interactive without a shell... – kstratis – 2012-07-14T23:59:24.843

1One could argue that, but it all depends on how WinSCP uses the SSH protocol. – Fran – 2012-07-15T00:01:17.327