Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
    return
fi

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Maybe standard method of checking the fd ’0′ ?

if [ -t 0 ]; then
# do stuff
fi
share|improve this answer
    
I added a NOT to the beginning - so at the top of my code I have: if [ ! -t 0 ]; then return fi –  Brad Apr 30 '13 at 11:52
    
Thank you so much for the help! –  Brad Apr 30 '13 at 11:52
    
Yep, "NOT" will do it. No worries. –  Danila Ladner Apr 30 '13 at 12:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.