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


Java FileSystemFile类代码示例

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


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

示例1: uploadFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的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: receiveFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
public void receiveFile(String lfile, String rfile) throws Exception {
	final SSHClient ssh = getConnectedClient();

	try {
		final Session session = ssh.startSession();
		try {
			ssh.newSCPFileTransfer().download(rfile, new FileSystemFile(lfile));
		} catch (SCPException e) {
			if (e.getMessage().contains("No such file or directory"))
				logger.warn("No file or directory `{}` found on {}.", rfile, ip);
			else
				throw e;
		} finally {
			session.close();
		}
	} finally {
		ssh.disconnect();
		ssh.close();
	}
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:21,代码来源:Sshj.java

示例3: downloadFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的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: copyFilesFromLocalDisk

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Override
public void copyFilesFromLocalDisk(Path srcPath, String destRelPath) throws IOException {
  LOGGER.trace("copyFilesFromLocalDisk({}, {})", srcPath.toString(), destRelPath);
  mkdirs(destRelPath);

  // Must be correct, because mkdirs has passed.
  String remotePath = concatenatePathToHome(destRelPath);

  SSHClient ssh = connectWithSSH();
  try {
    ssh.useCompression();

    ssh.newSCPFileTransfer().upload(new FileSystemFile(srcPath.toFile()), remotePath);
  } finally {
    ssh.disconnect();
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:18,代码来源:SSHEnvironment.java

示例5: copyFilesToLocalDisk

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Override
public void copyFilesToLocalDisk(String srcRelPath, Path destPath) throws IOException {
  LOGGER.trace("copyFilesToLocalDisk({}, {})", srcRelPath, destPath.toString());
  createDestinationDirectoriesLocally(destPath);

  SSHClient ssh = connectWithSSH();
  try {
    ssh.useCompression();

    String remotePath = concatenatePathToHome(srcRelPath);

    ssh.newSCPFileTransfer().download(remotePath, new FileSystemFile(destPath.toFile()));
  } finally {
    ssh.disconnect();
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:17,代码来源:SSHEnvironment.java

示例6: upload

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
/**
 * Uploads a local file (or directory) to the remote server via SCP.
 *
 * @param address the hostname or IP address of the remote server.
 * @param username the username of the remote server.
 * @param password the password of the remote server.
 * @param localPath a local file or directory which will be uploaded.
 * @param remotePath the destination path on the remote server.
 * @throws Exception
 */
public void upload(String address, String username, String password, String localPath, String remotePath) throws Exception {
	SSHClient client = newSSHClient();
	client.connect(address);
	logger.debug("Connected to hostname %s", address);
	try {
		client.authPassword(username, password.toCharArray());
		logger.debug("Successful authentication of user %s", username);

		client.newSCPFileTransfer().upload(new FileSystemFile(new File(localPath)), remotePath);
		logger.debug("Successful upload from %s to %s", localPath, remotePath);
	} finally {
		client.disconnect();
		logger.debug("Disconnected to hostname %s", address);
	}
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:26,代码来源:SSH.java

示例7: download

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
/**
 * Downloads a remote file (or directory) to the local directory via SCP.
 * 
 * @param address the hostname or IP address of the remote server.
 * @param username the username of the remote server.
 * @param password the password of the remote server.
 * @param remotePath a remote file or directory which will be downloaded.
 * @param localPath the destination directory on the local file system.
 * @throws Exception
 */
public void download(String address, String username, String password, String remotePath, String localPath) throws Exception {
	SSHClient client = newSSHClient();
	client.connect(address);
	logger.debug("Connected to hostname %s", address);
	try {
		client.authPassword(username, password.toCharArray());
		logger.debug("Successful authentication of user %s", username);

		client.newSCPFileTransfer().download(remotePath, new FileSystemFile(new File(localPath)));
		logger.debug("Successful download from %s to %s", remotePath, localPath);
	} finally {
		client.disconnect();
		logger.debug("Disconnected to hostname %s", address);
	}
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:26,代码来源:SSH.java

示例8: updateAgentConfigurationFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
/**
 * Updates the configuration file of an agent.
 * @param parameters
 * @param ssh
 * @param tmpDir
 * @param keyToNewValue
 * @throws IOException
 */
void updateAgentConfigurationFile(
		TargetHandlerParameters parameters,
		SSHClient ssh,
		File tmpDir,
		Map<String,String> keyToNewValue )
throws IOException {

	this.logger.fine( "Updating agent parameters on remote host..." );

	// Update the agent's configuration file
	String agentConfigDir = Utils.getValue( parameters.getTargetProperties(), SCP_AGENT_CONFIG_DIR, DEFAULT_SCP_AGENT_CONFIG_DIR );
	File localAgentConfig = new File( tmpDir, Constants.KARAF_CFG_FILE_AGENT );
	File remoteAgentConfig = new File( agentConfigDir, Constants.KARAF_CFG_FILE_AGENT );

	// Download remote agent config file...
	ssh.newSCPFileTransfer().download(remoteAgentConfig.getCanonicalPath(), new FileSystemFile(tmpDir));

	// Replace "parameters" property to point on the user data file...
	String config = Utils.readFileContent(localAgentConfig);
	config = Utils.updateProperties( config, keyToNewValue );
	Utils.writeStringInto(config, localAgentConfig);

	// Then upload agent config file back
	ssh.newSCPFileTransfer().upload(new FileSystemFile(localAgentConfig), agentConfigDir);
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:34,代码来源:ConfiguratorOnCreation.java

示例9: getTempLocalInstance

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的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

示例10: download

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Override
public void download(final String source, final File destination) throws IOException {

    final SFTPClient sftp = ssh.newSFTPClient();
    LOGGER.debug("downloading {} from host {} to {}", source, getName(), destination);
    sftp.get(source, new FileSystemFile(destination));
}
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:8,代码来源:SSHHost.java

示例11: upload

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
private void upload(final SFTPClient sftp, final File file, final String destination) throws IOException {

        final String path = FilenameUtils.getFullPath(destination);
        LOGGER.debug("path to make on remote {}", path);
        sftp.mkdirs(path);
        sftp.put(new FileSystemFile(file), destination);
    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:8,代码来源:SSHHost.java

示例12: sendFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
public void sendFile(String lfile, String rfile) throws Exception {
	final SSHClient ssh = getConnectedClient();

	try {
		final Session session = ssh.startSession();
		try {
			ssh.newSCPFileTransfer().upload(new FileSystemFile(lfile), rfile);
		} finally {
			session.close();
		}
	} finally {
		ssh.disconnect();
		ssh.close();
	}
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:16,代码来源:Sshj.java

示例13: testUpload_1

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Test
public void testUpload_1() throws Exception {
	when(client.newSCPFileTransfer()).thenReturn(scpTransfer);
	
	ssh.upload("127.0.1.1", "username", "password", "file", "/tmp");
	
	verify(client, times(1)).connect("127.0.1.1");
	verify(client, times(1)).authPassword("username", "password".toCharArray());
	verify(client, times(1)).newSCPFileTransfer();
	verify(scpTransfer, times(1)).upload(new FileSystemFile(new File("file")), "/tmp");
	
	verify(client, times(1)).disconnect();
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:14,代码来源:SSHTest.java

示例14: testDownload_1

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Test
public void testDownload_1() throws Exception {
	when(client.newSCPFileTransfer()).thenReturn(scpTransfer);
	
	ssh.download("127.0.1.1", "username", "password", "/var/log", "download");
	
	verify(client, times(1)).connect("127.0.1.1");
	verify(client, times(1)).authPassword("username", "password".toCharArray());
	verify(client, times(1)).newSCPFileTransfer();
	verify(scpTransfer, times(1)).download("/var/log", new FileSystemFile(new File("download")));
	
	verify(client, times(1)).disconnect();
}
 
开发者ID:cyron,项目名称:byteman-framework,代码行数:14,代码来源:SSHTest.java

示例15: prepareConfiguration

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
Map<String,String> prepareConfiguration( TargetHandlerParameters parameters, SSHClient ssh, File tmpDir )
throws IOException {

	// Generate local user-data file
	String userData = UserDataHelpers.writeUserDataAsString(
			parameters.getMessagingProperties(),
			parameters.getDomain(),
			parameters.getApplicationName(),
			parameters.getScopedInstancePath());

	File userdataFile = new File(tmpDir, USER_DATA_FILE);
	Utils.writeStringInto(userData, userdataFile);

	// Then upload it
	this.logger.fine( "Uploading user data as a file..." );
	String agentConfigDir = Utils.getValue( parameters.getTargetProperties(), SCP_AGENT_CONFIG_DIR, DEFAULT_SCP_AGENT_CONFIG_DIR );
	ssh.newSCPFileTransfer().upload( new FileSystemFile(userdataFile), agentConfigDir);

	// Update the agent's configuration file
	Map<String,String> keyToNewValue = new HashMap<> ();
	File remoteAgentConfig = new File(agentConfigDir, userdataFile.getName());

	// Reset all the fields
	keyToNewValue.put( AGENT_APPLICATION_NAME, "" );
	keyToNewValue.put( AGENT_SCOPED_INSTANCE_PATH, "" );
	keyToNewValue.put( AGENT_DOMAIN, "" );

	// The location of the parameters must be an URL
	keyToNewValue.put( AGENT_PARAMETERS, remoteAgentConfig.toURI().toURL().toString());

	return keyToNewValue;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:33,代码来源:ConfiguratorOnCreation.java


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