List of usage examples for org.apache.commons.vfs2 FileSystemOptions FileSystemOptions
public FileSystemOptions()
From source file:SftpClientFactory.java
public static void main(String args[]) throws FileSystemException { String hostName = "commentpool-baggio000.rhcloud.com"; String username = "529ddb964382eca06f0004b0"; String password = "1026wu"; // Create SFTP options FileSystemOptions opts = new FileSystemOptions(); // // SSH Key checking // SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking( // opts, "yes"); ///*from w ww.j a v a 2 s . c om*/ // // Root directory set to user home // SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); // // // Timeout is count by Milliseconds // SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); SftpFileSystemConfigBuilder.getInstance().setIdentities(opts, new File[] { new File("baggio_openssh.ppk") }); createConnection(hostName, 22, username.toCharArray(), password.toCharArray(), opts); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java
public static void uploadFile(String accntName, String acctHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//from w w w . j a v a 2 s. co m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, acctHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java
public static void uploadFile(String accntName, String accntHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//from w ww . j a v a 2s. co m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.nesscomputing.velocity.CommonsVfsResourceLoader.java
@Override public InputStream getResourceStream(String source) throws ResourceNotFoundException { try {//from w ww . j ava2s.c o m FileSystemOptions opts = new FileSystemOptions(); return VFS.getManager().resolveFile(source, opts).getContent().getInputStream(); } catch (FileSystemException e) { LOG.debug(String.format("Could not load resource \"%s\"", source), e); throw new ResourceNotFoundException(source, e); } }
From source file:hpmonitoringaudit.sftp.java
public boolean startFTP(String propertiesFilename, String fileToDownload) { props = new Properties(); StandardFileSystemManager manager = new StandardFileSystemManager(); try {//w w w . jav a 2 s .c o m props.load(new FileInputStream("properties/" + propertiesFilename)); String serverAddress = props.getProperty("serverAddress").trim(); String userId = props.getProperty("userId").trim(); String password = props.getProperty("password").trim(); String remoteDirectory = props.getProperty("remoteDirectory").trim(); String localDirectory = props.getProperty("localDirectory").trim(); //Initializes the file manager manager.init(); //Setup our SFTP configuration FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); //Create the SFTP URI using the host name, userid, password, remote path and file name String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + remoteDirectory + fileToDownload; // Create local file object String filepath = localDirectory + fileToDownload; File file = new File(filepath); FileObject localFile = manager.resolveFile(file.getAbsolutePath()); // Create remote file object FileObject remoteFile = manager.resolveFile(sftpUri, opts); // Copy local file to sftp server localFile.copyFrom(remoteFile, Selectors.SELECT_SELF); System.out.println("File download successful"); } catch (Exception ex) { ex.printStackTrace(); return false; } finally { manager.close(); } return true; }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java
@Test public void testSetAuthenticator() throws Exception { DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().build(); FileSystemOptions opts = new FileSystemOptions(); DeployOperatorBase operatorBase = (DeployOperatorBase) operator; operatorBase.setAuthenticator(opts, "user", "password"); UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts); Assert.assertNotNull(auth);/* ww w .j a v a2s. c o m*/ }
From source file:fr.cls.atoll.motu.processor.wps.TestVFS.java
public static void testBugDoReplicateFile() { StandardFileSystemManager standardFileSystemManager = new StandardFileSystemManager(); standardFileSystemManager.setLogger(LogFactory.getLog(VFS.class)); standardFileSystemManager.setClassLoader(TestVFS.class.getClassLoader()); try {/*from w w w . ja va2s .c o m*/ URL configUrl = new URL( "file:/J:/dev/atoll-v2/atoll-motu/atoll-motu-library/src/main/resources/motuVFSProvider.xml"); standardFileSystemManager.setConfiguration(configUrl); standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL); standardFileSystemManager.init(); String uri = "jar:file:/C:/Documents%20and%20Settings/dearith/.m2/repository/org/jvnet/ogc/iso-19139-d_2006_05_04-schema/1.0.0-PATCH-CLS/iso-19139-d_2006_05_04-schema-1.0.0-PATCH-CLS.jar!/schema/iso19139"; FileSystemOptions opts = new FileSystemOptions(); FileObject fileObject = standardFileSystemManager.resolveFile(uri, opts); } catch (FileSystemException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.codehaus.mojo.vfs.FileSystemOptionsFactory.java
public FileSystemOptions getFileSystemOptions(String url, String username, String password) throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); String[] tokens = StringUtils.split(url, ":"); String protocol = tokens[0];/*from w w w. jav a 2 s . com*/ if ("ftp".equals(protocol)) { FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance(); builder.setPassiveMode(opts, ftpSettings.isPassiveMode()); builder.setUserDirIsRoot(opts, ftpSettings.isUserDirIsRoot()); } if ("sftp".equals(protocol)) { SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setUserDirIsRoot(opts, sftpSettings.isUserDirIsRoot()); } String domain = null; tokens = StringUtils.split("\\"); if (tokens.length == 2) { domain = tokens[0]; username = tokens[1]; } StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); return opts; }
From source file:com.connection.factory.SftpConnectionApacheLib.java
@Override public boolean getConnection() { if (command != null) { closeConnection();/*www. j a va 2s . c om*/ } FileSystemOptions fso = new FileSystemOptions(); try { SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "no"); SftpFileSystemConfigBuilder.getInstance().setTimeout(fso, 5000); session = SftpClientFactory.createConnection(_ipAdress, _port, _userName.toCharArray(), _passWord.toCharArray(), fso); Channel channel = session.openChannel("sftp"); command = (ChannelSftp) channel; channel.connect(); System.out.println("Connected to " + _ipAdress + " via sFTP"); return true; } catch (FileSystemException | JSchException e) { System.out.println("Connection Failed to " + _ipAdress); return false; } }
From source file:com.collective.celos.ci.deploy.JScpWorker.java
public FileSystemOptions getSftpDefaultOptions() throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setPreferredAuthentications(opts, DEFAULT_SECURITY_SETTINGS); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); return opts;/*ww w. j av a2s. com*/ }