当前位置: 首页>>代码示例>>Java>>正文


Java SftpClient.cd方法代码示例

本文整理汇总了Java中com.sshtools.j2ssh.SftpClient.cd方法的典型用法代码示例。如果您正苦于以下问题:Java SftpClient.cd方法的具体用法?Java SftpClient.cd怎么用?Java SftpClient.cd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sshtools.j2ssh.SftpClient的用法示例。


在下文中一共展示了SftpClient.cd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putFileToRemoteHost

import com.sshtools.j2ssh.SftpClient; //导入方法依赖的package包/类
/**
 * Put file to remote host.
 *
 * @param host the hostname of the client
 * @param port the port number the user want to use for connection
 * @param username the username required for authentication
 * @param password the password required for authentication
 * @param localfilePath the localfile path where the file is situated
 * @param remotePath the remote path where the file is going to be put
 * @param fileName the file name you want to put
 * @throws IOException Signals that an I/O exception has occurred.
 */
@SuppressWarnings("unchecked")
public static void putFileToRemoteHost(String host, int port,String username,String password, String localfilePath,String remotePath,String fileName)throws IOException {
	SftpClient sftp = getSftpClient(host,port, username, password);
	sftp.lcd(localfilePath);
	sftp.cd(remotePath);
	sftp.put(fileName);
	List<SftpFile> dirContents = sftp.ls(remotePath);
    Iterator<SftpFile> it = dirContents.iterator();
    while(it.hasNext()){    		  
    	if(it.next().getFilename().equals(fileName)){
    		 SSH_LOG.info("The file " + fileName + " was tranferred successfully to " + remotePath);
    		 return;
    	}
    }
    SSH_LOG.error("The file " + fileName + " was not tranferred  to " + remotePath);	
}
 
开发者ID:persado,项目名称:stevia,代码行数:29,代码来源:SSHUtils.java

示例2: getFileFromRemoteHost

import com.sshtools.j2ssh.SftpClient; //导入方法依赖的package包/类
/**
 * Gets the file from remote host.
 *
 * @param host the hostname of the client
 * @param port the port number the user want to use for connection
 * @param username the username required for authentication
 * @param password the password required for authentication
 * @param remoteFilePath remotePath the remote path from where the file is going to be get
 * @param localfilePath the local file path where the file is going to be put
 * @param fileName the name of the file you want to transfer
 * @return the file from the remote host
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void getFileFromRemoteHost(String host, int port,String username,String password, String remoteFilePath,String localPath,String fileName) throws IOException {
	SftpClient sftp = getSftpClient(host, port,username, password);
	sftp.cd(remoteFilePath);
	sftp.lcd(localPath);
	sftp.get(fileName);
	File f = new File(localPath+System.getProperty("file.separator")+fileName);
	if (!f.exists()){
		SSH_LOG.error("The file " + fileName + " was not tranferred  to " + localPath);	
	}
	else{
		SSH_LOG.info("The file " + fileName + " was tranferred successfully to " + localPath);
	}		
}
 
开发者ID:persado,项目名称:stevia,代码行数:27,代码来源:SSHUtils.java

示例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);
  }
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:73,代码来源:SftpConnect.java


注:本文中的com.sshtools.j2ssh.SftpClient.cd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。