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


Java SSHClient.newSFTPClient方法代码示例

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


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

示例1: uploadFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void uploadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  final SSHClient ssh = new SSHClient();
  ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));

  ssh.connect("localhost", subject.getPort());
  try {
    ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
        KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));

    final SFTPClient sftp = ssh.newSFTPClient();
    File testFile = local.newFile("fred.txt");
    try {
      sftp.put(new FileSystemFile(testFile), "/fred.txt");
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(sftpHome.getRoot().list(), is(new String[]{"fred.txt"}));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:24,代码来源:TestSftpRule.java

示例2: transferEvents

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private void transferEvents(SSHClient sshClient, List<MotionEvent> motionEvents) throws IOException, ParseException {
    for (MotionEvent motionEvent : motionEvents) {
        ByteArraySourceFile byteArraySourceFile = new ByteArraySourceFile.Builder()
                .fileData(motionEvent.getImage())
                .name(motionEvent.getId() + ".jpg")
                .build();
        String day = concurrentDateFormatAccess.convertDateToString(motionEvent.getTimestamp());
        SFTPClient sftpClient = sshClient.newSFTPClient();
        String destinationPath = eyeballsConfiguration.getSftpDestinationDirectory() + "/" + day + "/";
        sftpClient.mkdirs(destinationPath);
        sftpClient.put(byteArraySourceFile, destinationPath);
    }
}
 
开发者ID:chriskearney,项目名称:eyeballs,代码行数:14,代码来源:SftpMotionEventConsumer.java

示例3: downloadFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void downloadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  FileUtils.write(sftpHome.newFile("fred.txt"), "Electric boogaloo");

  final SSHClient ssh = new SSHClient();
  ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));

  ssh.connect("localhost", subject.getPort());
  try {
    ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
        KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));

    final SFTPClient sftp = ssh.newSFTPClient();

    try {
      sftp.get("fred.txt", new FileSystemFile(new File(local.getRoot(), "fred.txt")));
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(FileUtils.readFileToString(new File(local.getRoot(), "fred.txt")),
      is("Electric boogaloo"));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:27,代码来源:TestSftpRule.java

示例4: getTempLocalInstance

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public File getTempLocalInstance( String remoteFilePath )
{
  File tempFile = null;
  SSHClient client = new SSHClient();
  // required if host is not in knownLocalHosts
  client.addHostKeyVerifier(new PromiscuousVerifier());

  try {
    client.connect(hostName);
    client.authPassword(userName, userPass);

    tempFile = File.createTempFile("tmp", null, null);
    tempFile.deleteOnExit();

    SFTPClient sftp = client.newSFTPClient();
    sftp.get(remoteFilePath, new FileSystemFile(tempFile));
    sftp.close();
    client.disconnect();

  } catch( Exception e ) { 
    //TODO: this needs to be more robust than just catching all exceptions
    e.printStackTrace();
    logger.error( e.toString() );
    return null;
  } 
  
  return tempFile;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:29,代码来源:SshClientJ.java

示例5: listFiles

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void listFiles() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  sftpHome.newFile("fred.txt");
  List<RemoteResourceInfo> files;

  final SSHClient ssh = new SSHClient();
  ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));

  ssh.connect("localhost", subject.getPort());
  try {
    ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
        KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));

    final SFTPClient sftp = ssh.newSFTPClient();

    try {
      files = sftp.ls("/");
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(files.size(), is(1));
  assertThat(files.get(0).getName(), is("fred.txt"));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:28,代码来源:TestSftpRule.java

示例6: listFilesUsingNativeSystem

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
protected Set<FileInfo> listFilesUsingNativeSystem(LogAccessConfig logAccessConfig, String subPath) throws LogAccessException {
	
	// Get ssh client
	SSHClient sshClient = sshClientThreadLocal.get();

	// Define target directory
	String targetPath = logAccessConfig.getDirectory();
	if (subPath != null) {
		targetPath += "/" + subPath;
	}

	// List files and directories (keep only the 'fileListMaxCount' last modified resources)
	SFTPClient sftpClient = null;
	Collection<RemoteResourceInfo> remoteResourceInfos;
	try {
		sftpClient = sshClient.newSFTPClient();
		LastUpdatedRemoteResourceFilter remoteResourcefilter = new LastUpdatedRemoteResourceFilter(configService.getFileListMaxCount());
		sftpClient.ls(targetPath, remoteResourcefilter);
		remoteResourceInfos = remoteResourcefilter.getRemoteResourceInfos();
	}
	catch (IOException e) {
		throw new LogAccessException("Error when listing files and directories on " + logAccessConfig, e);
	}
	finally {
		IOUtils.closeQuietly(sftpClient, sshClient);
	}
	
	// Extract meta-informations
	Set<FileInfo> fileInfos = new TreeSet<FileInfo>();
	for (RemoteResourceInfo remoteResourceInfo : remoteResourceInfos) {
		FileInfo fileInfo = new FileInfo();
		fileInfo.setFileName(remoteResourceInfo.getName());
		fileInfo.setRelativePath(remoteResourceInfo.getPath().substring(logAccessConfig.getDirectory().length() + 1).replace('\\', '/'));
		fileInfo.setDirectory(remoteResourceInfo.isDirectory());
		fileInfo.setLastModified(new Date(remoteResourceInfo.getAttributes().getMtime() * 1000L));
		fileInfo.setFileSize(remoteResourceInfo.isDirectory() ? 0L : remoteResourceInfo.getAttributes().getSize());
		fileInfo.setLogAccessType(LogAccessType.SSH);
		fileInfos.add(fileInfo);
	}
	
	// Return meta-informations about files and folders
	return fileInfos;
}
 
开发者ID:fbaligand,项目名称:lognavigator,代码行数:45,代码来源:SshLogAccessService.java

示例7: mkdirs

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
 * Create directories in environment if they don't exist. If directoryPath consists of several
 * directories all required parent directories are created as well.
 *
 * @param directoryPath path to create
 */
public void mkdirs(String directoryPath) throws IOException {
  LOGGER.trace("mkdirs({})", directoryPath);
  String finalDirectoryPath = concatenatePathToHome(directoryPath);
  FilenameUtils.normalize(finalDirectoryPath, true);
  if (!finalDirectoryPath.startsWith("/")) {
    // SFTP mkdirs requires to a dot for relative path, otherwise it assumes given path is
    // absolute.
    finalDirectoryPath = "./" + finalDirectoryPath;
  }

  SSHClient ssh = connectWithSSH();
  try {
    try {
      try (SFTPClient sftp = ssh.newSFTPClient()) {
        sftp.mkdirs(finalDirectoryPath);
      }
    } catch (IOException e) {
      // SFTP has failed (on some systems it may be just disabled) revert to mkdir.
      List<String> command = new ArrayList<>();
      command.add("mkdir");
      command.add("-p");
      command.add(finalDirectoryPath);
      String sshHomeDir = ".";
      int exitStatus = runCommand(command, ssh, sshHomeDir);
      if (exitStatus != 0) {
        throw new IOException("Could not create suggested directories.");
      }
    }
  } finally {
    ssh.disconnect();
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:39,代码来源:SSHEnvironment.java

示例8: client

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public SFTPClient client() throws IOException {
    final SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(new PublicKeyVerifier(hostKey.publicKey()));
    ssh.connect("localhost", port);

    createdClients.add(ssh);

    if (null == password) {
        ssh.authPublickey(user, new KeyPairWrapper(keyPair));
    } else {
        ssh.authPassword(user, password);
    }

    return ssh.newSFTPClient();
}
 
开发者ID:signed,项目名称:in-memory-infrastructure,代码行数:16,代码来源:SftpClientBuilder.java

示例9: getFilesInPath

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public ArrayList< String > getFilesInPath( String path ) 
{
  ArrayList< String > ret = new ArrayList< String >();

  SSHClient client = new SSHClient();
  client.addHostKeyVerifier(new PromiscuousVerifier());

  try {
    client.connect(hostName);
    client.authPassword(userName, userPass);

    SFTPClient sftp                  = client.newSFTPClient();
    List< RemoteResourceInfo > files = sftp.ls( path );
    for( RemoteResourceInfo file: files )
    {
      ret.add( file.getPath() );
    }

    sftp.close();
    client.disconnect();

  } catch( Exception e ) {
    logger.error( e.toString() );
  } 

  return ret;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:28,代码来源:SshClientJ.java


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