使用“exec”进行JSch SCP文件传输渠道 [英] JSch SCP file transfer using "exec" channel
问题描述
我是SCP协议和JSch的新手。我必须通过SCP将文件从远程设备传输到Android。服务器端开发人员拒绝告诉他们有关他们设备的任何信息,除了文件位置和可用于通过SCP访问它的root帐户。
I'm very new to the SCP protocol and JSch. I have to transfer a file fro a remote device via SCP to Android. The server side developers refused to tell be anything about their device except for the file location, and the root account which can be used to access it with SCP.
这是我试过的步骤。
-
确认使用JSch,我的Android客户端可以与服务器建立连接。 [完整]
Confirm that using JSch, my Android client can establish connection with the server. [complete]
确认使用JSch和 ChannelExec
对象,我可以发送 ls
命令并读取其输出。 [完整]
Confirm that using JSch, and the ChannelExec
object, I can send the ls
command and read its output. [complete]
确认使用JSch和 ChannelSFTP
对象,我可以从中传输文件装置。 [失败]
Confirm that using JSch, and the ChannelSFTP
object, I can transfer a file from the device. [failed]
(3)失败的原因似乎是没有为SFTP配置设备(服务器)。制造商继续说下面的ssh上的命令有效:
The reason why (3) failed seems that the device (server) is not configured for SFTP. The maker keeps on saying that commands on ssh like below works:
scp root@192.168.5.1/usr/WS026.jpeg [targetPath]
他们说上面的命令会将第一个参数复制到客户端的目标路径。那么,替代使用SFTP,我如何在JSch频道exec中实现它?
They say that the above command will copy the first parameter to the target path of the client. So, alternative to using the SFTP, how can I implement that in JSch channel "exec"?
推荐答案
如果设备仅支持SCP,请不要尝试使用SFTP,使用SCP。
If the device supports SCP only, do not try to use SFTP, use SCP.
有一个使用JSch实现SCP下载的官方示例:
http://www.jcraft.com/jsch/examples/ ScpFrom.java.html
There's an official example for implementing the SCP download using the JSch:
http://www.jcraft.com/jsch/examples/ScpFrom.java.html
不要对 scp的调用感到困惑
在示例代码中。这就是SCP协议的工作原理。本地(OpenSSH) scp
在远程服务器上执行 scp
(具有特定的非公开参数,在本例中为 -f
)然后这两个实例相互通信。该示例实现了本地 scp
。用于远程 scp
的参数不是您用于本地 scp
的参数。
Do not get confused by the call of scp
in the example code. That's how SCP protocol works. A local (OpenSSH) scp
executes the scp
on the remote server (with specific non-public arguments, in this case the -f
) and then the two instances talk to each other. The example implements the local scp
. The arguments used for the remote scp
are not the arguments you would use for the local scp
.
另请参阅 JSch库中的SCP协议实施说明。
这篇关于使用“exec”进行JSch SCP文件传输渠道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!