本文整理汇总了Java中com.sshtools.j2ssh.SftpClient.quit方法的典型用法代码示例。如果您正苦于以下问题:Java SftpClient.quit方法的具体用法?Java SftpClient.quit怎么用?Java SftpClient.quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sshtools.j2ssh.SftpClient
的用法示例。
在下文中一共展示了SftpClient.quit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sftpUpload
import com.sshtools.j2ssh.SftpClient; //导入方法依赖的package包/类
/***********************************************************************/
public static void sftpUpload(FTPConfig config, File file, String remoteFileName) throws IOException
{
SshClient ssh = new SshClient();
SftpClient sftp = sshLogin(config, ssh);
sftp.mkdirs(remoteFileName.substring(0, remoteFileName.lastIndexOf("/")));
sftp.put(new FileInputStream(file), remoteFileName);
sftp.quit();
ssh.disconnect();
}
示例2: sftpDownload
import com.sshtools.j2ssh.SftpClient; //导入方法依赖的package包/类
/************************************************************************/
public static File sftpDownload(FTPConfig config, File file, String remoteFileName) throws IOException
{
SshClient ssh = new SshClient();
SftpClient sftp = sshLogin(config, ssh);
sftp.get(remoteFileName, new FileOutputStream(file));
sftp.quit();
ssh.disconnect();
return file;
}
示例3: main
import com.sshtools.j2ssh.SftpClient; //导入方法依赖的package包/类
/**
* The main program for the PasswordConnect class
*
* @param args The command line arguments
*/
public static void main(String args[]) {
try {
// Setup a logfile
/*Handler fh = new FileHandler("example.log");
fh.setFormatter(new SimpleFormatter());
Logger.getLogger("com.sshtools").setUseParentHandlers(false);
Logger.getLogger("com.sshtools").addHandler(fh);
Logger.getLogger("com.sshtools").setLevel(Level.ALL);*/
// Configure J2SSH (This will attempt to install the bouncycastle provider
// under jdk 1.3.1)
ConfigurationLoader.initialize(false);
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("Connect to host? ");
String hostname = reader.readLine();
// Make a client connection
SshClient ssh = new SshClient();
// Connect to the host
ssh.connect(hostname);
// Create a password authentication instance
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
// Get the users name
System.out.print("Username? ");
String username = reader.readLine();
pwd.setUsername(username);
// Get the password
System.out.print("Password? ");
String password = reader.readLine();
pwd.setPassword(password);
// Try the authentication
int result = ssh.authenticate(pwd);
// Evaluate the result
if (result == AuthenticationProtocolState.COMPLETE) {
// The connection is authenticated we can now do some real work!
SftpClient sftp = ssh.openSftpClient();
// Make a directory
try {
sftp.mkdir("j2ssh");
}
catch (IOException ex) {
}
// Change directory
sftp.cd("j2ssh");
System.out.println(sftp.pwd());
// Change the mode
sftp.chmod(0777, "j2ssh");
sftp.lcd("c:/");
// Upload a file
sftp.put("system.gif");
// Change the local directory
sftp.lcd("localdir");
// Download a file
sftp.get("somefile.txt", "anotherfile.txt");
// Remove a directory or file
sftp.rm("j2ssh");
// Quit
sftp.quit();
ssh.disconnect();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
System.exit(0);
}
}