• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SftpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SftpClient类属于com.sshtools.j2ssh包,在下文中一共展示了SftpClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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();
}
 
开发者ID:approvals,项目名称:ApprovalTests.Java,代码行数:11,代码来源:NetUtils.java


示例4: sshLogin

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/************************************************************************/
private static SftpClient sshLogin(FTPConfig config, SshClient ssh) throws IOException
{
  ssh.setSocketTimeout(60000);
  ssh.connect(config.host, new IgnoreHostKeyVerification());
  PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
  pwd.setUsername(config.userName);
  pwd.setPassword(config.password);
  ssh.authenticate(pwd);
  SftpClient sftp = ssh.openSftpClient();
  return sftp;
}
 
开发者ID:approvals,项目名称:ApprovalTests.Java,代码行数:13,代码来源:NetUtils.java


示例5: 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;
}
 
开发者ID:approvals,项目名称:ApprovalTests.Java,代码行数:11,代码来源:NetUtils.java


示例6: getFTP

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
public SftpClient getFTP() {
	return ftp;
}
 
开发者ID:wtsi-medical-genomics,项目名称:evoker,代码行数:4,代码来源:DataClient.java


示例7: 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


示例8: configureUserAccess

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/**
*
*
* @param sftp
* @param serverId
* @param system
* @param username
* @param pk
* @param authorizationFile
* @param mode
*
* @return
*
* @throws RemoteIdentificationException
*/
    public boolean configureUserAccess(SftpClient sftp, String serverId,
        String system, String username, SshPublicKey pk,
        String authorizationFile, int mode)
        throws RemoteIdentificationException {
        Vector keys = new Vector();
        keys.add(pk);

        return configureUserAccess(sftp, serverId, system, username, keys,
            authorizationFile, mode);
    }
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:26,代码来源:RemoteIdentification.java


示例9: getSftpClient

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/**
 * Create an SFTP connection to a client
 * 
 * @param host the hostname of the Client.The default port used for connection is 22
 * @param username the username required for authentication
 * @param password the password required for authentication
 * @return the client 
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static SftpClient getSftpClient(String host, String username,String password) throws IOException {
	return getSftpClient(host, SSH_PORT, username, password);
}
 
开发者ID:persado,项目名称:stevia,代码行数:13,代码来源:SSHUtils.java


示例10: openSftpClient

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/**
 * Implementation of the SessionManager method, this simply calls the SshClient
* method openSftpClient.
* @return
* @throws IOException
*/
    public SftpClient openSftpClient() throws IOException {
        return ssh.openSftpClient();
    }
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:10,代码来源:SessionProviderFrame.java


示例11: openSftpClient

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/**
* Opens an SftpClient on the managed connection.
*
* @return
*
* @throws IOException
*/
    public SftpClient openSftpClient() throws IOException;
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:9,代码来源:SessionManager.java


示例12: openSftpClient

import com.sshtools.j2ssh.SftpClient; //导入依赖的package包/类
/**
     * Implementation of the SessionManager method, this simply calls the SshClient
 * method openSftpClient.
 * @return
 * @throws IOException
 */
public SftpClient openSftpClient() throws IOException {
  return ssh.openSftpClient();
}
 
开发者ID:UniversityofWarwick,项目名称:j2ssh-fork,代码行数:10,代码来源:SessionProviderInternalFrame.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FileTreeElement类代码示例发布时间:2022-05-23
下一篇:
Java BlurTransformation类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap