JSch库中SCP协议实现的解释

5

我正在思考JSch库使用的一个示例,可以在这里找到:
http://www.jcraft.com/jsch/examples/ScpFrom.java.html

我无法理解这个示例中的几个代码模式。它们是:

  1. Is there any reasons to prefer SCP over SFTP, which can be ran using the same library?

  2. Why we run scp -f <remote file> on remote host instead of running simply scp source_file_path destination_file_path? Why execution on remote host is better?

  3. In the beginning of the transfer there is a line

    while(true){
    int c=checkAck(in);
    if(c!='C'){
        break;
    }
    ...
    

    what is the meaning of this magical C letter? Why C?

  4. Why to send this signal all the time?

    // send '\0'
    buf[0]=0; out.write(buf, 0, 1); out.flush();
    
  5. how this can read filesize?

    long filesize=0L;
    while(true){
        if(in.read(buf, 0, 1)<0){
            // error
            break; 
        }
        if(buf[0]==' ')break;
        filesize=filesize*10L+(long)(buf[0]-'0'); //What is this??
    }
    
1个回答

13

C<filesize> <filename>

So the size of the file is explicitly sent as part of the command, allowing the receiving end to know the expected size of the following transfer.

C permissions size filename
例如:
C 0644 153634 index.php

代码中的循环将字符串"153634"转换为数字153634。看起来实现有点复杂,但它有效。


另请参阅SCP(安全拷贝协议)文件传输是如何工作的?


相关:http://superuser.com/questions/134901/whats-the-difference-between-scp-and-sftp - VGR

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接