When I attempt to Secure FTP (using WinSCP) to my CentOS 6.4 box I'm prompted with a message that states:

Received too large (168438314 B) SFTP packet. Max supported packet size is 1024000 B.

This error is typically caused by message printed from startup script (like profile). The message may start with ""\n\n**"" 

Cannot initialize SFTP protocol. Is the host running an SFTP server

This appears to be caused by my /etc/profile.d/custom.sh script which gets run during login. Its setup to output a welcome message, as well as a system summary (CPU/Memory/Disk Usage).

I really need the custom.sh script to run when logging into the local console OR when logging in via SSH. However I don't want it to run when logging into Secure FTP (SFTP).

Is there some way to configure it not to run when logging in via Secure FTP?

Or alternatively if I can't stop it from running is there a way I can detect that its being run during a secure FTP login and not output anything. So in pseudo code something like:

If logged in via secure FTP then output nothing Else if logged in via SSH or Local Console output message of the day (system stats).

Thanks! Brad

UPDATE - There is documentation supporting this issue here: http://winscp.net/eng/docs/requirements#remote_environment

The suggestion is to detect if the session is interactive or not. I tried doing that by adding the following to the top of my custom.sh but its still not working:

if [ -z $PS1 ]; then
### if [ -v PS1 ]   # On Bash 4.2+ ...
    # non-interactive

Then the rest of my script runs outputting the MOTD.

Should SecureFTP be detected as non-interactive or interactive? If its non-interactive why isn't the code above existing the script when I attempt to login via Secure FTP?

2 Answers 2


Maybe standard method of checking the fd ’0′ ?

if [ -t 0 ]; then
# do stuff
  • I added a NOT to the beginning - so at the top of my code I have: if [ ! -t 0 ]; then return fi
    – Brad
    Commented Apr 30, 2013 at 11:52
  • Yep, "NOT" will do it. No worries. Commented Apr 30, 2013 at 12:16

Using /etc/profile.d for de facto dynamic MOTD needed only for interactive logins over SSH/console will generate such issues.

While the workaround in Danila Lander's answer may work, I suggest doing the right thing and using a proper solution for that.

Please see this question's answers for info on how to do it the right way on Ubuntu and Centos 7 servers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .