SFTP 之使用 openssh

纯属备忘用:

First download the setupssh.exe package and then install  the openssh

After install the software, use the command window to CD to the folder : %install_folder%/OpenSSH/bin

Then type the command show below:

mkgroup -l >> ..\etc\group

mkpasswd -l >> ..\etc\passwd

 

 Then to type the command show below to start the sftp server:

net start opensshd

 

show the message : started successfully

 

Then you can use java code to test the connection

 

 

To stop the sftp server use the command below:

net stop opensshd

 

*******************************************************

Java来连接SFTP服务器 需要使用的jar包:jcraft.jar   (com.jcraft.jsdh.*)     *

64-bit windows can not support this

*******************************************************


--------------------------------------------------------------------------分割线----------------------------------------------------------------------------------

JCRAFT源码分析:

关键是 com.jcraft.jsch.JSch.java 这个类,有个全局的静态变量 :java.util.Hashtable config=new java.util.Hashtable();

里面有一些属性,主要是这个: config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password");

这里面的属性针对了四种验证方式。

当 com.jcraft.jsch.Session.java 这个类调用connect方法的时候,会去和服务器建立连接,服务器返回支持的验证方式

循环PreferredAuthentications这里面的四种验证模式和服务器返回的支付方式,发现有一样的,就调用的相应的实现类尝试和服务器建立连接

比如 gssapi-with-mic 不符合就调用下一个服务器支持的验证方式,直到找到一个能连接的,否则就抛出异常了。


怎么去找对应连接的实现类的呢?

Jsch 这个类的静态变量还有这几个属性:

    config.put("userauth.none",    "com.jcraft.jsch.UserAuthNone");
    config.put("userauth.password",    "com.jcraft.jsch.UserAuthPassword");
    config.put("userauth.keyboard-interactive",    "com.jcraft.jsch.UserAuthKeyboardInteractive");
    config.put("userauth.publickey",    "com.jcraft.jsch.UserAuthPublicKey");
    config.put("userauth.gssapi-with-mic",    "com.jcraft.jsch.UserAuthGSSAPIWithMIC");
    config.put("gssapi-with-mic.krb5",    "com.jcraft.jsch.jgss.GSSContextKrb5");
循环 "gssapi-with-mic,publickey,keyboard-interactive,password" 的时候,每次加 
userauth. 然后根据新生成的string静态变量 config里面找实现类,然后通过反射加载。。

先到这里,有空再研究。。。。。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值