我正在使用net.schmizz.sshj.xfer.scp.SCPFileTransfer类将文件从本地上传到远程服务器。它与以下错误失败:在期待响应协议消息的同时获取net.schmizz.sshj.xfer.scp.SCPException:EOF。同时将文件从linux上传到windows
net.schmizz.sshj.xfer.scp.SCPException: EOF while expecting response to protocol message. Additional info:
bash: -c: line 0: unexpected EOF while looking for matching bash: -c: line 1: syntax error: unexpected end of file
此问题我只在远程计算机是Windows时面临。对于Linux机器,它已成功上传。 我已经在我的代码中尝试了以下步骤。 1.将文件从远程机器下载到本地 2.再次将相同的文件上传回远程。
它未能在步骤2中
@Override
public boolean upload(String localLocation, String remoteLocation) throws SSHClientException {
this.ensureConnected();
SCPFileTransfer scp = this.sshj.newSCPFileTransfer();
try {
scp.upload(localLocation, remoteLocation);
} catch (IOException e) {
log.error("Failed to copy file {} from local path at {} to remote location {} at {}" + remoteLocation,
hostname, localLocation, e);
return false;
}
return true;
}
任何线索将是很有益的。
谢谢。
你知道,Windows和Linux处理的文件格式不同? 'CR LF'在Windows中使用,而Linux只使用'LF'。我会检查这些文件是如何编码的以及SCP如何处理文件格式。 您是否还检查过远程服务器是否接受该文件? – Nico
我cygwin安装在我的Windows机器,并按照每个cygdrive传递路径。路径看起来像“/ cygdrive/c/temp file /” –
错误消息表明传递给远程系统(调用scp)的命令格式错误。它有不匹配的引用或类似。您的'remoteLocation'中是否有任何引号字符,或者远程系统上的shell可能特殊的任何其他非字母数字字符? – Kenster