예제 #1
0
 public FileObjectProxy(FTPConfig config) {
   super();
   this.ftpConfig = config;
   connectionString =
       String.format(
           "%s://%s:%s%s",
           config.getType().toString().toLowerCase(),
           config.getHost(),
           config.getPort(),
           config.getWorkDir());
 }
예제 #2
0
 public FileObject connectAndChangeToWorkDir() throws FileSystemException {
   StaticUserAuthenticator auth =
       new StaticUserAuthenticator(null, ftpConfig.getUsername(), ftpConfig.getPassword());
   FileSystemOptions opts = new FileSystemOptions();
   switch (ftpConfig.getType()) {
     case FTP:
       FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, SOCKET_TIMEOUT);
       FtpFileSystemConfigBuilder.getInstance().setDataTimeout(opts, DATA_TIMEOUT);
       FtpFileSystemConfigBuilder.getInstance().setConnectTimeout(opts, CONNET_TIMEOUT);
       break;
     case FTPS:
       FtpsFileSystemConfigBuilder.getInstance().setSoTimeout(opts, SOCKET_TIMEOUT);
       FtpsFileSystemConfigBuilder.getInstance().setDataTimeout(opts, DATA_TIMEOUT);
       FtpsFileSystemConfigBuilder.getInstance().setConnectTimeout(opts, CONNET_TIMEOUT);
       break;
     case SFTP:
       SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, SOCKET_TIMEOUT);
       break;
   }
   DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
   FileObject fo = VFS.getManager().resolveFile(connectionString, opts);
   LOG.info("connected at {} #{}", connectionString, ftpConfig.getId());
   return fo;
 }