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

Java FileSystemFile类代码示例

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

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



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


示例16: download

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Override
public void download(String remotePath, Path local) throws IOException {
    try (SFTPClient sftpClient = sshClient.newSFTPClient()) {
        sftpClient.get(remotePath, new FileSystemFile(local.toFile()));
    }
}
 
开发者ID:sparsick,项目名称:comparison-java-ssh-libs,代码行数:7,代码来源:SshJClient.java


示例17: upload

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Override
public void upload(Path local, String remotePath) throws IOException {
    try (SFTPClient sFTPClient = sshClient.newSFTPClient()) {
        sFTPClient.put(new FileSystemFile(local.toFile()), remotePath);
    }
}
 
开发者ID:sparsick,项目名称:comparison-java-ssh-libs,代码行数:7,代码来源:SshJClient.java


示例18: testUpdateAgentConfigurationFile

import net.schmizz.sshj.xfer.FileSystemFile; //导入依赖的package包/类
@Test
public void testUpdateAgentConfigurationFile() throws Exception {

	// Prepare the mocks
	File tmpDir = this.folder.newFolder();
	File agentConfigurationFile = new File( tmpDir, Constants.KARAF_CFG_FILE_AGENT );

	Properties props = new Properties();
	props.setProperty( "a0", "c0" );
	props.setProperty( "a1", "c213" );
	props.setProperty( "a2", "c2" );
	props.setProperty( "a3", "c3" );
	props.setProperty( "a4", "c4" );
	props.setProperty( "a5", "c5" );
	Utils.writePropertiesFile( props, agentConfigurationFile );

	TargetHandlerParameters parameters = new TargetHandlerParameters()
			.targetProperties( new HashMap<String,String>( 0 ));

	final Map<String,String> keyToNewValue = new HashMap<> ();
	keyToNewValue.put( "a1", "b1" );
	keyToNewValue.put( "a2", "b2" );
	keyToNewValue.put( "a3", "b3" );

	SSHClient ssh = Mockito.mock( SSHClient.class );
	SCPFileTransfer scp = Mockito.mock( SCPFileTransfer.class );
	Mockito.when( ssh.newSCPFileTransfer()).thenReturn( scp );

	// Invoke the method
	EmbeddedHandler embedded = new EmbeddedHandler();
	embedded.karafData = this.folder.newFolder().getAbsolutePath();
	ConfiguratorOnCreation configurator = new ConfiguratorOnCreation( parameters, "ip", "machineId", embedded );
	configurator.updateAgentConfigurationFile( parameters, ssh, tmpDir, keyToNewValue );

	// Verify
	ArgumentCaptor<String> remotePathCaptor = ArgumentCaptor.forClass( String.class );
	ArgumentCaptor<FileSystemFile> fileCaptor = ArgumentCaptor.forClass( FileSystemFile.class );
	Mockito.verify( scp ).download( remotePathCaptor.capture(), fileCaptor.capture());

	Assert.assertEquals( tmpDir, fileCaptor.getValue().getFile());
	Assert.assertEquals(
			new File( DEFAULT_SCP_AGENT_CONFIG_DIR, Constants.KARAF_CFG_FILE_AGENT ).getAbsolutePath(),
			remotePathCaptor.getValue());

	// 1st: we upload the user data
	// 2nd: we reupload the same file than the one we downloaded
	ArgumentCaptor<String> remotePathCaptor2 = ArgumentCaptor.forClass( String.class );
	ArgumentCaptor<FileSystemFile> fileCaptor2 = ArgumentCaptor.forClass( FileSystemFile.class );
	Mockito.verify( scp ).upload( fileCaptor2.capture(), remotePathCaptor2.capture());

	Assert.assertEquals( agentConfigurationFile.getAbsolutePath(), fileCaptor2.getValue().getFile().getAbsolutePath());
	Assert.assertEquals( DEFAULT_SCP_AGENT_CONFIG_DIR, remotePathCaptor2.getValue());

	// And no additional call
	Mockito.verifyNoMoreInteractions( scp );
	Mockito.verify( ssh, Mockito.times( 2 )).newSCPFileTransfer();
	Mockito.verifyNoMoreInteractions( ssh );

	// Verify the properties were correctly updated in the file
	Properties readProps = Utils.readPropertiesFile( agentConfigurationFile );
	Assert.assertEquals( "c0", readProps.get( "a0" ));
	Assert.assertEquals( "b1", readProps.get( "a1" ));
	Assert.assertEquals( "b2", readProps.get( "a2" ));
	Assert.assertEquals( "b3", readProps.get( "a3" ));
	Assert.assertEquals( "c4", readProps.get( "a4" ));
	Assert.assertEquals( "c5", readProps.get( "a5" ));
	Assert.assertEquals( props.size(), readProps.size());

	// Prevent a compilation warning about leaks
	configurator.close();
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:72,代码来源:ConfiguratorOnCreationTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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