先要在网上下个SSH.jar包,我要用的是一些文件相关的操作,以下是一个简单的例子。 package test; import java.io.IOException; import java.util.List; import com.sshtools.j2ssh.SshClient; import com.sshtools.j2ssh.authentication.AuthenticationProtocolState; import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; import com.sshtools.j2ssh.sftp.SftpFile; /** * * @author qianj * @version 1.0.0 * @2011-3-31 下午06:44:56 */ public class Test { public static void main(String[] args) { SshClient client = new SshClient(); try { client.connect("192.168.20.133", 22);//IP和端口 //设置用户名和密码 PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); pwd.setUsername("root"); pwd.setPassword("111111"); int result = client.authenticate(pwd); if (result == AuthenticationProtocolState.COMPLETE) {//如果连接完成 List<SftpFile> list = client.openSftpClient().ls("./Desktop/hehe"); for (SftpFile f : list) { System.out.println(f.getFilename()); System.out.println(f.getAbsolutePath()); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }