sftp连接服务器失败

实际工作例子:

在windows上用XShell工具时,某服务器长时间都没有反应。

但是ssh登录仍然可以正常连接。

换用linux上的sftp命令来连接时,出现了一些错误信息:

[[email protected] ~]# sftp -o Port=5555 [email protected]:/usr/local/gdns/
Connecting to 192.168.18.15...
[email protected]‘s password:
Received message too long 1131376761


原因在于服务端的.bashrc中有存在标准输出的语句

[[email protected] etc]# cat ~/.bashrc

# .bashrc
# User specific aliases and functions
alias rm=‘rm -i‘
alias cp=‘cp -i‘
alias mv=‘mv -i‘
# Source global definitions
if [ -f /etc/bashrc ]; then
     . /etc/bashrc
fi
source /opt/intel/vtune_amplifier_xe_2013/amplxe-vars.sh


最后一个脚本程序会输出:

Copyright (C) 2009-2014 Intel Corporation. All rights reserved.
Intel(R) VTune(TM) Amplifier XE 2013 (build 353306)


需要把这些输出去掉,因此改为

source /opt/intel/vtune_amplifier_xe_2013/amplxe-vars.sh 1>/dev/null 2>&1


根据SFTP中的相关说明,输出字符的前4个字节"Copy"每个字母按照ASCII值拼接在一起被翻译成32位整数,十六进制是436F7079,十进制就是1131376761, 在传输协议中是作为包长度字段的,因此这是一个非常大的数字,导致连接出错。

附上相关的FAQ

SSH Frequently Asked Questions

When I try to use sftp or scp2, I get a message like this:

Received message too long (or "Bad packet length") 1416586337

and the connection fails. What‘s wrong?



sftp and scp2 both actually work by running ssh in a subprocess, to connect to the remote host and run the file-transfer server (usually named sftp-server). For instance, the command sftp server might result in the following command being run (OpenSSH):

ssh server -s -oForwardX11=no -oForwardAgent=no -oProtocol=2 sftp

scp2/sftp and sftp-server use a special file-transfer protocol, which they speak over this SSH session. The protocol is in fact based on the same packet protocol used by SSH.

In order for this to work, the SSH session must be "clean" — that is, it must have on it only information transmitted by the programs at either end. What often happens, though, is that there are statements in either the system or per-user shell startup files on the server (.bashrc.profile/etc/csh.cshrc.login, etc.) which output text messages on login, intended to be read by humans (like fortuneecho "Hi there!", etc.). Such code should only produce output on interactive logins, when there is a tty attached to standard input. If it does not make this test, it will insert these text messages where they don‘t belong: in this case, polluting the protocol stream between scp2/sftp and sftp-server. The first four bytes of the text gets interpreted as a 32-bit packet length, which will usually be a wildly large number, provoking the error message above. Notice that:

1416586337 decimal = 546F6461 hex = "Toda" ASCII

suggesting a string beginning "Today..." (or maybe "Thank-you" in transliterated Hebrew).

The reason the shell startup files are relevant at all, is that sshd employs the user‘s shell when starting any programs on the user‘s behalf (using e.g. /bin/sh -c "command"). This is a Unix tradition, and has advantages:

  • The user‘s usual setup (command aliases, environment variables, umask, etc.) are in effect when remote commands are run.
  • The common practice of setting an account‘s shell to /bin/false to disable it will prevent the owner from running any commands, should authentication still accidentally succeed for some reason.

There has been a lot of argument about whether this is the right behavior, since having sshd instead exec sftp-server directly, without the shell, would avoid this frequent problem. I personally feel that using the shell is the right thing to do: having startup files that emit text messages when there is no user to read them is just a mistake. SSH2 has a Boolean configuration statement AllowCshrcSourcingWithSubsystems, set false by default, which causes sshd2 to pass the -f flag to the shell when running subsystem programs (sftp-server is run as an SSH-2 "subsystem"). With most shells, -f causes the shell to omit the normal startup file processing. This prevents the corruption problem, but introduces other difficulties. With file transfers, the umask setting is important, and people are confused when they find that the umask they set in their ~/.login file works with random remote commands (e.g. ssh server touch foo), but is mysteriously ignored when using scp2/sftp.

时间: 2024-10-08 20:39:48

sftp连接服务器失败的相关文章

ERROR: ORA-28547: 连接服务器失败, 可能是 Oracle Net 管理错误

问题:当使用远程连接时出现 ERROR: ORA-28547: 连接服务器失败, 可能是 Oracle Net 管理错误 解决: 1.查看监听状态,发现不是我定义的orcl 2.使用Net Configuration Assistant从新配置listener.ora 3.修改listener.ora 4.重启服务 5.验证

oracle11g ORA-28547:连接服务器失败,可能是Oracle Net管理错误

解决办法: (PROGRAM = extproc)  把这句话去掉重启监听服务 extproc是一个扩展的程序调用接口协议,  连接和调用外部的操作系统程序或进程用时会用到. 原文地址:https://www.cnblogs.com/tengtengteng/p/9037003.html

android studio 更新时连接服务器失败

windows下的解决方法: 如果是运行的是32位的android studio需要在修改一下文件: 在andriod studio的启动目录下.找到studio.exe.vmoptions这个文件.在后面加上 -Djava.net.preferIPv4Stack=true -Didea.updates.url=http://dl.google.com/android/studio/patches/updates.xml  -Didea.patches.url=http://dl.google.

FileZilla连接ftp服务器失败,提示"AUTH TLS"解决方法

FileZilla连接ftp服务器失败,提示"AUTH TLS"解决方法 前几天还是能正常连接ftp服务器的,突然一下连接失败,提示"AUTH TLS",用浏览器试了一下"ftp:ip地址",输入用户名.密码后可以正常访问.所以应该是FileZilla软件连接配置有点问题,百度了一下就解决了.记录下解决过程,方便自己查看. 1.连接的提示 连接时并没有提示用户名.密码错误,说明是正确的:查了下,原因是服务器不支持FTP over TLS的连接方式

CENTOS 配置好SVN服务环境后,其他服务器无法访问 Error: Can't connect to host '192.168.1.103': 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

CENTOS 配置好SVN服务环境后,其他服务器无法访问 根据 下面的步骤配置好服务后,使用本机可以正常 连接到 SVN 服务, 但是使用局域网的其他服务器访问时出现下面的错误, Error: Can't connect to host '192.168.1.103': 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败. 时由于防火墙配置问题, 需修改防火墙规则,或者使用下面的命令把防火墙服务关闭即可 service iptables stop 配置自动启动:把svnserv

SFTP远程连接服务器上传下载文件-vs2010项目实例

本项目仅测试远程连接服务器,支持上传,下载文件,更多功能开发请看API自行开发. 环境:win7系统,vs2010 vs2010项目实例下载地址:CSDN下载 如果没有CSDN积分,百度网盘下载(密码:uxnt) 文件目录介绍: 1.libssh2.sln是vs2010的解决方案,用vs2010打开(如图1所示): include是需要导入的头文件,lib是需要使用的lib文件(如图2所示): 图1 图2 2.解决方案:"libssh2"(如图3所示) 这里只需要编译运行demo项目即

PhpStorm连接服务器,开始自动上传功能

连接服务器 菜单栏找到[工具/Tools]->[Deployment/部署]->[Confinguration-/配置-]. 点加号(+),添加一台服务器,填写名称,选择类型为SFTP,点击确定. 按下图提示,填写服务器信息. 填写完服务器链接信息,点击[Test SFTP Connection-]测试SFTP连接. 正在通过SFTP连接. 提示成功:成功地连接到*********(IP地址). 提示失败:连接到"*********(IP地址)"失败了.会话.连接:java

升级VMware Horizon View虚拟桌面到6.2之3-升级View连接服务器

10.3 升级View连接服务器 本节介绍View连接服务器的系统需求,以及升级的步骤. 10.3.1 View连接服务器系统需求 View 连接服务器充当客户端连接代理,负责执行身份验证并将传入的用户请求定向到相应的远程桌面和应用程序.View 连接服务器(包括标准.副本和安全服务器安装)具有特定的硬件.操作系统.安装和支持软件要求. 1 View 连接服务器支持的操作系统 您必须在支持的 Windows Server 操作系统上安装 View 连接服务器. 表10-4列表了View 连接服务

python socket连接服务器获取回显

军训回来了,皮皮..... import socket import sys try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #创建一个服务器之间的连接,使用TCP连接 except socket.error as e: print("报错了?,我也很无奈啊"+e) sys.exit() host="www.baidu.com" port=80 try: jsip=socket.gethostbynam