Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
953 views
in Technique[技术] by (71.8m points)

java - JSch SCP file transfer using "exec" channel

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.

Here are the steps I tried.

  1. Confirm that using JSch, my Android client can establish connection with the server. [complete]

  2. Confirm that using JSch, and the ChannelExec object, I can send the ls command and read its output. [complete]

  3. Confirm that using JSch, and the ChannelSFTP object, I can transfer a file from the device. [failed]

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]

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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If the device supports SCP only, do not try to use SFTP, use SCP.

There's an official example for implementing the SCP download using the JSch:
http://www.jcraft.com/jsch/examples/ScpFrom.java.html


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.

See also Explanation for SCP protocol implementation in JSch library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...