纯属备忘用:
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里面找实现类,然后通过反射加载。。
先到这里,有空再研究。。。。。