本文整理汇总了Java中org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder类的典型用法代码示例。如果您正苦于以下问题:Java SftpFileSystemConfigBuilder类的具体用法?Java SftpFileSystemConfigBuilder怎么用?Java SftpFileSystemConfigBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SftpFileSystemConfigBuilder类属于org.apache.commons.vfs2.provider.sftp包,在下文中一共展示了SftpFileSystemConfigBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadFilesToServer
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Uploads files using SFTP.
* Used for sending files from the machine to the main files server.
*/
public void uploadFilesToServer() throws Throwable {
try {
handleStopInterrupt();
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
fsManager = VFS.getManager();
File folder = new File(localDir);
recursiveUploadDirectory(opts, folder);
} catch (FileSystemException ex) {
handleIfItCausedByInterrupt(ex);
logger.error("[Study = " + taskStudy + "] [Unit = " + unitId + "] sftp error", ex);
throw new NetworkException(ex.getMessage());
}
return;
}
示例2: createDefaultFileSystemOptions
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
protected FileSystemOptions createDefaultFileSystemOptions() throws FileSystemException {
FileSystemOptions opts = new FileSystemOptions();
// SSH Key checking
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
// VFS file system root:
// setting this parameter false = cause VFS to choose File System's Root as VFS's root
// setting this parameter true = cause VFS to choose user's home directory as VFS's root
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
// Timeout is count by Milliseconds
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 20000);
return opts;
}
示例3: setProxyType
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
public static SftpFileSystemConfigBuilder setProxyType(SftpFileSystemConfigBuilder builder, FileSystemOptions fsOptions, ProxyTask.ProxyType type)
{
SftpFileSystemConfigBuilder.ProxyType setType = null;
switch (type) {
case HTTP:
setType = SftpFileSystemConfigBuilder.PROXY_HTTP;
break;
case SOCKS:
setType = SftpFileSystemConfigBuilder.PROXY_SOCKS5;
break;
case STREAM:
setType = SftpFileSystemConfigBuilder.PROXY_STREAM;
}
builder.setProxyType(fsOptions, setType);
return builder;
}
示例4: resolveFileObject
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Returns a file representation
*
* @param filePath The file path
* @return a file representation
* @throws FileSystemException
*/
public static FileObject resolveFileObject(String filePath) throws FileSystemException {
LOGGER.info("Resolving file: {}", filePath);
if (filePath.startsWith("sftp://")) {
SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
builder.setStrictHostKeyChecking(opts, "no");
builder.setUserDirIsRoot(opts, false);
builder.setCompression(opts, "zlib,none");
} else if (filePath.startsWith("smb://")) {
} else if (filePath.startsWith("ftp://")) {
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
}
UserAuthenticatorFactory factory = new UserAuthenticatorFactory();
OtrosUserAuthenticator authenticator = factory.getUiUserAuthenticator(persistentAuthStore, sessionAuthStore, filePath, opts);
if (pathContainsCredentials(filePath)) {
authenticator = null;
}
return resolveFileObject(filePath, opts, authenticator, persistentAuthStore, sessionAuthStore);
}
示例5: resolveFileObject
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Returns a file representation
* @param filePath The file path
* @return a file representation
*/
public static FileObject resolveFileObject(String filePath)
{
try
{
if (filePath.startsWith("sftp://"))
{
SftpFileSystemConfigBuilder.getInstance()
.setStrictHostKeyChecking(opts, "no");
}
return getFileSystemManager().resolveFile(filePath, opts);
}
catch (FileSystemException ex)
{
return null;
}
}
示例6: setKnownHosts
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
public void setKnownHosts(final String hostFile) {
if (!"".equals(hostFile)) {
try {
SftpFileSystemConfigBuilder.getInstance().setKnownHosts(opts,
new File(hostFile));
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
示例7: setIdentity
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
public void setIdentity(final String identFile) {
if (!"".equals(identFile)) {
try {
SftpFileSystemConfigBuilder.getInstance().setIdentities(opts,
new File[] { new File(identFile) });
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
示例8: authSetup
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws FileSystemException {
String username = description.getParameter(ConnectionDescription.PARAMETER_USERNAME);
String password = description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD);
StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
SftpFileSystemConfigBuilder cfg = SftpFileSystemConfigBuilder.getInstance();
//TODO: add cfg.setUserDirIsRoot(opts, false); and handle profile updates
if (null != SSH_DIR_NAME) {
cfg.setKnownHosts(options, new File(SSH_DIR_NAME, "known_hosts"));
}
logger.debug("SFTP using knownHosts: ", cfg.getKnownHosts(options));
cfg.setUserInfo(options, this);
cfg.setStrictHostKeyChecking(options, "ask");
if ("enabled".equals(description.getParameter("publicKeyAuth"))) {
cfg.setPreferredAuthentications(options, "publickey,password,keyboard-interactive");
}
else {
cfg.setPreferredAuthentications(options, "password,keyboard-interactive");
}
}
示例9: recognizesAndSetsIdentityKeyFile
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
@Test
public void recognizesAndSetsIdentityKeyFile() throws Exception {
File tempFile = File.createTempFile( "KettleSftpFileSystemConfigBuilderTest", ".tmp" );
tempFile.deleteOnExit();
final String fullName = "vfs.sftp.identity";
final String name = fullName.substring( "vfs.sftp.".length() );
final String vfsInternalName = SftpFileSystemConfigBuilder.class.getName() + ".IDENTITIES";
final FileSystemOptions opts = new FileSystemOptions();
KettleSftpFileSystemConfigBuilder builder = KettleSftpFileSystemConfigBuilder.getInstance();
builder.setParameter( opts, name, tempFile.getAbsolutePath(), fullName, "sftp://fake-url:22" );
Method getOption = ReflectionUtils.findMethod( opts.getClass(), "getOption", Class.class, String.class );
getOption.setAccessible( true );
Object value = ReflectionUtils.invokeMethod( getOption, opts, builder.getConfigClass(), vfsInternalName );
assertEquals( IdentityInfo[].class, value.getClass() );
assertEquals( tempFile.getAbsolutePath(), ( (IdentityInfo[]) value )[0].getPrivateKey().getAbsolutePath() );
}
示例10: getFilesFromServerByDirectory
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
private void getFilesFromServerByDirectory(String currRemotelDir, Optional<String> fileRegex) throws Throwable {
handleStopInterrupt();
String currSftpUri = "sftp://" + user + ":" + password + "@" + machine + currRemotelDir + "/";
try {
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
fsManager = VFS.getManager();
// List all the files in that directory.
FileObject localFileObject=fsManager.resolveFile(currSftpUri,opts);
FileObject[] children = localFileObject.getChildren();
for ( int i = 0; i < children.length; i++ ){
handleStopInterrupt();
String fileName = children[ i ].getName().getBaseName();
if ((fileName.contains("%"))) {
continue;
}
if ((fileRegex.isPresent()) && !(fileName.matches(fileRegex.get()))) {
logger.info("[Study = " + taskStudy + "] [Unit = " + unitId + "]File " + fileName + " doesn't match pattern " + fileRegex.get());
continue;
}
String filepath = localDir + File.separator + fileName;
File file = new File(filepath);
FileObject localFile = fsManager.resolveFile(file.getAbsolutePath(),opts);
FileObject remoteFile = fsManager.resolveFile(currSftpUri+ File.separator + fileName, opts);
localFile.copyFrom(remoteFile, Selectors.SELECT_SELF);
logger.info("[Study = " + taskStudy + "] [Unit = " + unitId + "] File downloaded successfully: " + fileName);
}
} catch (FileSystemException ex) {
handleIfItCausedByInterrupt(ex);
logger.error("[Study = " + taskStudy + "] [Unit = " + unitId + "] sftp error", ex);
throw new NetworkException(ex.getMessage());
}
return;
}
示例11: init
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public void init(String storeId) {
super.init(storeId);
uri = MCRConfiguration.instance().getString(storeConfigPrefix + "URI");
String check = MCRConfiguration.instance().getString(storeConfigPrefix + "StrictHostKeyChecking", "no");
try {
fsManager = VFS.getManager();
opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, check);
FileObject baseDir = getBase();
// Create a folder, if it does not exist or throw an
// exception, if baseDir is not a folder
baseDir.createFolder();
if (!baseDir.isWriteable()) {
String msg = "Content store base directory is not writeable: " + uri;
throw new MCRConfigurationException(msg);
}
} catch (FileSystemException ex) {
throw new MCRException(ex.getCode(), ex);
}
}
示例12: createDefaultOptions
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Get the default options for File system
*
* @return
* @throws FileSystemException
*/
public static FileSystemOptions createDefaultOptions() throws FileSystemException {
FileSystemOptions opts = new FileSystemOptions();
// SSH Key checking
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
// Root directory set to user home
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
// Timeout is count by Milliseconds
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 100000);
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, 100000);
FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
return opts;
}
示例13: initializeFsOptions
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
private FileSystemOptions initializeFsOptions(PluginTask task)
{
FileSystemOptions fsOptions = new FileSystemOptions();
try {
SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
builder.setUserDirIsRoot(fsOptions, task.getUserDirIsRoot());
builder.setTimeout(fsOptions, task.getSftpConnectionTimeout() * 1000);
builder.setStrictHostKeyChecking(fsOptions, "no");
if (task.getSecretKeyFilePath().isPresent()) {
IdentityInfo identityInfo = new IdentityInfo(
new File((task.getSecretKeyFilePath().transform(localFileToPathString()).get())),
task.getSecretKeyPassphrase().getBytes()
);
builder.setIdentityInfo(fsOptions, identityInfo);
logger.info("set identity: {}", task.getSecretKeyFilePath().get());
}
if (task.getProxy().isPresent()) {
ProxyTask proxy = task.getProxy().get();
ProxyTask.ProxyType.setProxyType(builder, fsOptions, proxy.getType());
if (proxy.getHost().isPresent()) {
builder.setProxyHost(fsOptions, proxy.getHost().get());
builder.setProxyPort(fsOptions, proxy.getPort());
}
if (proxy.getUser().isPresent()) {
builder.setProxyUser(fsOptions, proxy.getUser().get());
}
if (proxy.getPassword().isPresent()) {
builder.setProxyPassword(fsOptions, proxy.getPassword().get());
}
if (proxy.getCommand().isPresent()) {
builder.setProxyCommand(fsOptions, proxy.getCommand().get());
}
}
}
catch (FileSystemException e) {
logger.error(e.getMessage());
throw new ConfigException(e);
}
return fsOptions;
}
示例14: getAuthenticationData
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
protected void getAuthenticationData(UserAuthenticationData authenticationData) {
super.getAuthenticationData(authenticationData);
authenticationData.setData(UserAuthenticationDataWrapper.SSH_KEY, sshKeyFileField.getText().trim().toCharArray());
if (StringUtils.isNotBlank(sshKeyFileField.getText())) {
try {
SftpFileSystemConfigBuilder.getInstance().setIdentities(getFileSystemOptions(), new File[]{new File(sshKeyFileField.getText())});
//TODO set user auth data file path
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
示例15: buildConnectionOptions
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; //导入依赖的package包/类
private FileSystemOptions buildConnectionOptions() throws FileSystemException {
SftpFileSystemConfigBuilder sftpConfigBuilder = SftpFileSystemConfigBuilder.getInstance();
FileSystemOptions opts = new FileSystemOptions();
sftpConfigBuilder.setUserDirIsRoot(opts, false);
sftpConfigBuilder.setStrictHostKeyChecking(opts, "yes");
if (knownHosts != null) {
sftpConfigBuilder.setKnownHosts(opts, knownHosts.toFile());
} else {
sftpConfigBuilder.setKnownHosts(opts, new File("~/.ssh/known_hosts"));
}
if (privateKey != null) {
sftpConfigBuilder.setIdentities(opts, new File[]{privateKey.toFile()});
}
return opts;
}