Package org.globus.ftp

Examples of org.globus.ftp.GridFTPClient


     * @param gsCredential
     * @param localFile
     * @throws GfacException
     */
    public void downloadFile(URI destURI, GSSCredential gsCredential, File localFile) throws ToolsException {
        GridFTPClient ftpClient = null;
        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
        try {
            String remoteFile = destURI.getPath();

            log.info("The local temp file is " + localFile);
            log.info("the remote file is " + remoteFile);

            log.debug("Setup GridFTP Client");

            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
            ftpClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
            ftpClient.authenticate(gsCredential);
            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);

            log.debug("Downloading file");
            if (checkBinaryExtensions(remoteFile)) {
                log.info("Transfer mode is set to Binary to download a file");
                ftpClient.setType(Session.TYPE_IMAGE);
            }

            ftpClient.get(remoteFile, localFile);

            log.info("Download file to:" + remoteFile + " is done");

        } catch (ServerException e) {
            throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
        } catch (IOException e) {
            throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
        } catch (ClientException e) {
            throw new ToolsException("Cannot download file from GridFTP:" + contactInfo.toString(), e);
        } finally {
            if (ftpClient != null) {
                try {
                    ftpClient.close();
                } catch (Exception e) {
                    log.warn("Cannot close GridFTP client connection",e);
                }
            }
        }
View Full Code Here


     * @throws ServerException
     * @throws ClientException
     * @throws IOException
     */
    public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws ToolsException {
        GridFTPClient destClient = null;
        GridFTPClient srcClient = null;

        try {
            destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
            destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
            destClient.authenticate(gssCred);
            if (checkBinaryExtensions(desthost.getPath())) {
                log.info("Transfer mode is set to Binary");
                destClient.setType(Session.TYPE_IMAGE);
            }

            srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
            srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
            srcClient.authenticate(gssCred);
            if (checkBinaryExtensions(srchost.getPath())) {
                log.info("Transfer mode is set to Binary");
                srcClient.setType(Session.TYPE_IMAGE);
            }

            if (srcActive) {
                log.debug("Set src active");
                HostPort hp = destClient.setPassive();
                srcClient.setActive(hp);
            } else {
                log.debug("Set dst active");
                HostPort hp = srcClient.setPassive();
                destClient.setActive(hp);
            }

            log.debug("Start transfer file from GridFTP:" + srchost.toString() + " to " + desthost.toString());

            /**
             * Transfer a file. The transfer() function blocks until the transfer is complete.
             */
            srcClient.transfer(srchost.getPath(), destClient, desthost.getPath(), false, null);
            if (srcClient.getSize(srchost.getPath()) == destClient.getSize(desthost.getPath())) {
                log.debug("CHECK SUM OK");
            } else {
                log.debug("****CHECK SUM FAILED****");
            }

        } catch (ServerException e) {
            throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
                    + desthost.toString(), e);
        } catch (IOException e) {
            throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
                    + desthost.toString(), e);
        } catch (ClientException e) {
            throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
                    + desthost.toString(), e);
        } finally {
            if (destClient != null) {
                try {
                    destClient.close();
                } catch (Exception e) {
                    log.warn("Cannot close GridFTP client connection at Desitnation:" + desthost.toString());
                }
            }
            if (srcClient != null) {
                try {
                    srcClient.close();
                } catch (Exception e) {
                    log.warn("Cannot close GridFTP client connection at Source:" + srchost.toString(),e);
                }
            }
        }
View Full Code Here

   * @throws ToolsException
   */
    @SuppressWarnings("unchecked")
  public List<String> listDir(URI dirURI, GSSCredential gssCred) throws ToolsException {
      List<String> files = new  ArrayList<String>();
      GridFTPClient srcClient = null;
      try {
        GridFTPContactInfo contactInfo = new GridFTPContactInfo(dirURI.getHost(), dirURI.getPort());

        srcClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
        srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
        srcClient.authenticate(gssCred);
        srcClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
        srcClient.setType(Session.TYPE_ASCII);
        srcClient.changeDir(dirURI.getPath());

        Vector<Object> fileInfo = null;
        try {
          fileInfo = srcClient.mlsd();
        } catch (Throwable e) {
          fileInfo = srcClient.list();
        }

        if (!fileInfo.isEmpty()) {
          for (int j = 0; j < fileInfo.size(); ++j) {
            String name = null;
            if (fileInfo.get(j) instanceof MlsxEntry) {
              name = ((MlsxEntry) fileInfo.get(j)).getFileName();
            } else if (fileInfo.get(j) instanceof FileInfo) {
              name = ((FileInfo) fileInfo.get(j)).getName();
            } else {
              throw new ToolsException("Unsupported type returned by gridftp " + fileInfo.get(j));
            }

            if (!name.equals(".") && !name.equals("..")) {
              URI uri = GfacUtils.createGsiftpURI(contactInfo.hostName, dirURI.getPath() + File.separator + name);
              files.add(uri.getPath());
            }
          }
        }
        return files;
      } catch (IOException e) {
        throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
      } catch (ServerException e) {
        throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
      } catch (ClientException e) {
        throw new ToolsException("Could not list directory: " + dirURI.toString() ,e);
      } catch (URISyntaxException e) {
        throw new ToolsException("Error creating URL of listed files: " + dirURI.toString() ,e);
      } finally {
        if (srcClient != null) {
                  try {
                      srcClient.close();
                  } catch (Exception e) {
                      log.warn("Cannot close GridFTP client connection", e);
                  }
              }
    }
View Full Code Here

            .getHostName(), rootName.getPort(), rootName
            .getUserName(), rootName.getPassword(),
        // rootName.getPath(),
            getFileSystemOptions());
      } else {
        final GridFTPClient client = idleClient;
        idleClient = null;
        return client;
      }
    }
  }
View Full Code Here

        this.setupGridftpClient();
    }

    private void setupGridftpClient() throws Exception {
        System.out.println("host: ["+this.gridftpHost1+"] port: ["+this.gridftpPort1+"]");
        client = new GridFTPClient(this.gridftpHost1, this.gridftpPort1);
        client.authenticate(this.cred);

    }
View Full Code Here

    {
        // Create the file system
        final GenericFileName rootName = (GenericFileName) name;

        //Session session;
        GridFTPClient client;
        String attr_home;
        try
        {
            log.debug("Creating connection to GsiFTP Host:" + rootName.getHostName()
                + " Port:" + rootName.getPort()
                + " User:" + rootName.getUserName()
                + " Path:" + rootName.getPath());
         
          client = GsiFtpClientFactory.createConnection(rootName.getHostName(),
                  rootName.getPort(),
                  rootName.getUserName(),
                  rootName.getPassword(),
                  fileSystemOptions);

            //go to the home for the user
            client.changeDir("~");
            attr_home = client.getCurrentDir();
            log.debug("Current directory: " + attr_home);
        }
        catch (final Exception e)
        {
            throw new FileSystemException(e);
View Full Code Here

          //  throw new Exception("Password cannot be null");
         
          // Create a proxy cert (if missing)
          //new ProxyTool().createProxy(password);
         
          final GridFTPClient client = new GridFTPClient(hostname, port);

            try
            {
              // Authenticate w/ user credentials defines in $HOME/.globus/cog.properties
                //client.authenticate(null);
                GSSCredential credential = GsiFtpFileSystemConfigBuilder.getInstance().getCredential(fileSystemOptions);
                client.authenticate(credential);

                // Set binary mode
//                if (!client.setFileType(FTP.BINARY_FILE_TYPE))
//                {
//                    throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname);
//                }

                // Set dataTimeout value
//                Integer dataTimeout = FtpFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
//                if (dataTimeout != null)
//                {
//                    client.setDataTimeout(dataTimeout.intValue());
//                }

                // Change to root by default
                // All file operations a relative to the filesystem-root
                // String root = getRoot().getName().getPath();

//                Boolean userDirIsRoot = FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
//                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
//                {
//                    if (!client.changeWorkingDirectory(workingDirectory))
//                    {
//                        throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
//                    }
//                }
//
//                Boolean passiveMode = FtpFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
//                if (passiveMode != null && passiveMode.booleanValue())
//                {
//                    client.enterLocalPassiveMode();
//                }
            }
            catch (final IOException e)
            {
                if (client != null ) //.isConnected())
                {
                    client.close();
                }
                throw e;
            }

            return client;
View Full Code Here

            FileObject destFO, MarkerListener listener) throws IOException, Exception {

        log.debug("setupGridFtpThridPartyTransfer()");

        GridFtpFileSystem srcFS = (GridFtpFileSystem) srcFO.getFileSystem();
        GridFTPClient srcClient = srcFS.getClient();
        GridFtpFileSystem destFS = (GridFtpFileSystem) destFO.getFileSystem();
        GridFTPClient destClient = destFS.getClient();
        // create a new GridFTPUtil as this class is not stateless !
        GridFTPUtil gridftpUtil = new GridFTPUtil();
        gridftpUtil.setSourceClient(srcClient);
        gridftpUtil.setDestClient(destClient);
        gridftpUtil.setMarkerListener(listener);
View Full Code Here

    }

    static public  void doGridFtpThridPartyTransfer(GridFTPUtil gridftpUtil, FileObject srcFO,
            FileObject destFO, boolean append) throws IOException, Exception {

        GridFTPClient srcClient = gridftpUtil.getSourceClient();
        GridFTPClient destClient = gridftpUtil.getDestinationClient();

        if(srcClient == null)
        {
            GridFtpFileSystem srcFS = (GridFtpFileSystem) srcFO.getFileSystem();
            log.debug("Source client null - need to call getClient");
View Full Code Here

        Log log = LogFactory.getLog(VFSUtil.class);
        log.debug("setupGridFtpThridPartyTransfer()");

        GridFtpFileSystem srcFS = (GridFtpFileSystem) srcFO.getFileSystem();
        GridFTPClient srcClient = srcFS.getClient();
        GridFtpFileSystem destFS = (GridFtpFileSystem) destFO.getFileSystem();
        GridFTPClient destClient = destFS.getClient();
        // create a new GridFTPUtil as this class is not stateless !
        GridFTPUtil gridftpUtil = new GridFTPUtil();
        gridftpUtil.setSourceClient(srcClient);
        gridftpUtil.setDestClient(destClient);
        gridftpUtil.setMarkerListener(listener);
View Full Code Here

TOP

Related Classes of org.globus.ftp.GridFTPClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.