java - 从 windows 机器发送多个文件到 linux 远程服务器 "Jsch code"

标签 java scp jsch

smoeone 可以尝试使用 Jsch 将多个文件发送到远程服务器吗,这可能吗!!

我正在尝试发送多个脚本 perl 来检查远程服务器中的一些现有文件和命令,然后必须在我的本地机器上返回一个包含结果的文件,问题是我必须使用 eclipse那。

错误:

Bareword found where operator expected at /root/port.pl line 27, near "10.156.31.46 ssh"
    (Missing operator before ssh?)
Bareword found where operator expected at /root/port.pl line 27, near "8HcmdrGQDgXKL"
    (Missing operator before HcmdrGQDgXKL?)
Bareword found where operator expected at /root/port.pl line 27, near "9N1XgcLKUcC1DgFmcYoNLb1VsU9KYRhLAOGiIjWBdRkr6gLhZTJsnd2e464"
    (Missing operator before N1XgcLKUcC1DgFmcYoNLb1VsU9KYRhLAOGiIjWBdRkr6gLhZTJsnd2e464?)
Bareword found where operator expected at /root/port.pl line 27, near "2iIe3zJSlBH1tVd8PCifJaZ6Xu4KqsDFWjIILv8wY5XMWYdxVcPcMOsQhpl7vB2EgZxrc3yxE6rwfGnyxEKWez9W9t6e2hOvx3J21PxAGTaCIPjgxbcM4G"
    (Missing operator before iIe3zJSlBH1tVd8PCifJaZ6Xu4KqsDFWjIILv8wY5XMWYdxVcPcMOsQhpl7vB2EgZxrc3yxE6rwfGnyxEKWez9W9t6e2hOvx3J21PxAGTaCIPjgxbcM4G?)
syntax error at /root/port.pl line 27, near "10.156.31.46 ssh"
Execution of /root/port.pl aborted due to compilation errors.
exit-status: 255

当我使用 FileOutput 时出现此错误

java.io.FileNotFoundException: C:\Users\Computer\workspace\proj (Accès refusé)

最佳答案

是的,这可以很简单地完成。您需要打开一个 channel 并将二进制对象简单地放入 channel 中适当的位置。如果您想对多个文件执行此操作,您可以按顺序执行或连续提交给执行程序。

Session session = ...;// a new jSch Session with remote attributes (like ip, username and password)
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp csftp = (ChannelSftp) channel;

File file = new File(...); //binary file location to ftp
String fileAbsolutePath = ...;//The to location on remote server

csftp.put(new FileInputStream(file), fileAbsolutePath, file.length());

这当然是用jSch。有关更多信息,您可以查看此 example

关于java - 从 windows 机器发送多个文件到 linux 远程服务器 "Jsch code",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6251406/

相关文章:

java - 在@Configuration中注入(inject)合并的bean列表

c# - C# 中来自 SshNet 的 SshConnectionException

java - 如何使用 Jsch 递归地 FTP 目录结构?

java - 为使用 JSch 通过 SSH 执行的命令提供输入/子命令

java - 如何在J2me中制作 GridView

java - 在测试/最佳实践中访问 Junit 测试结果?

Java 正则表达式积极向前看但只匹配唯一字符?

perl - 如何在不发送文件的情况下检测远程主机是否提供 scp 服务?

linux - scp 或 pscp 将文件传输到 ssh 计算机,但不显示计算机中的任何复制文件

ssh - JSch 无法通过 Kerberos key 表文件连接