JSch - Explaining SCP stream reading [closed]

ⅰ亾dé卋堺 提交于 2019-12-10 12:09:11

问题


I'm having hard times trying to understand example codes from JSch library.

For example say, that I want to understand this code (example of scpFrom). I can't understand how that buffer, declared on line 56, works. How can that buffer contain for example read,write,execute flags, file size and first 7 chars of file name? I thought that when I read file with stream, that I'm reading contents of that file, not its filename etc...

Maybe I can't read Java documentation at all. I'm really confused by those examples and I don't want to use some library when I can't understand even examples :)

Can you suggest me what should I read or where are documented contents of that stream?
Another pearl for me is line 77, how can that code get filesize? 0 * 10L + first char in buff - char 0 ? I just don't get it...

Thank you all and sorry for my bad English.


回答1:


That code implements the SCP protocol. So the stream represents the protocol stream, not mere file contents.

One of the main SCP protocol commands is C that starts a file transfer.

The C command has syntax:

C<mode> <size> <name>

It's a human-readable string. The code you refer to, parses the string.


See also Explanation for SCP protocol implementation in JSch library.



来源:https://stackoverflow.com/questions/41636827/jsch-explaining-scp-stream-reading

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!