gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:48:26 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com