Examples of FileTransferClient


Examples of com.enterprisedt.net.ftp.FileTransferClient

        // set up logger so that we get some output
        Logger log = Logger.getLogger(TransferUsingStreams.class);
        Logger.setLevel(Level.INFO);

        FileTransferClient ftp = null;

        try {
            // create client
            log.info("Creating FTP client");
            ftp = new FileTransferClient();

            // set remote host
            ftp.setRemoteHost(host);
            ftp.setUserName(username);
            ftp.setPassword(password);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();
            log.info("Connected and logged in to server " + host);

            // byte array transfers
            String s1 = "Hello world";

            log.info("Putting s1");
            OutputStream out = ftp.uploadStream("Hello.txt");
            try {
                out.write(s1.getBytes());
            }
            finally {
                out.close(); // MUST be closed to complete the transfer
            }

            log.info("Retrieving as s2");
            StringBuffer s2 = new StringBuffer();
            InputStream in = ftp.downloadStream("Hello.txt");
            try {
                int ch = 0;
                while ((ch = in.read()) >= 0) {
                    s2.append((char)ch);
                }
            }
            finally {
                in.close(); // MUST be closed to complete the transfer
            }
               
            log.info("s1 == s2: " + s1.equals(s2.toString()));
           
            ftp.deleteFile("Hello.txt");

            // Shut down client
            log.info("Quitting client");
            ftp.disconnect();

            log.info("Example complete");

        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.enterprisedt.net.ftp.FileTransferClient

        // set up logger so that we get some output
        Logger log = Logger.getLogger(MonitorTransfersCommands.class);
        Logger.setLevel(Level.INFO);

        FileTransferClient ftp = null;

        try {
            // create client
            log.info("Creating FTP client");
            ftp = new FileTransferClient();

            // set remote host
            ftp.setRemoteHost(host);
            ftp.setUserName(username);
            ftp.setPassword(password);
           
            // set up listener
            ftp.setEventListener(new EventListenerImpl());
           
            // the transfer notify interval must be greater than buffer size
            ftp.getAdvancedSettings().setTransferBufferSize(500);
            ftp.getAdvancedSettings().setTransferNotifyInterval(1000);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();
            log.info("Connected and logged in to server " + host);

            log.info("Uploading file");
            String name = "MonitorTransfersCommands.java";

            // put the file
            ftp.uploadFile(name, name);
            log.info("File uploaded");

            // now delete remote file
            ftp.deleteFile(name);

            // Shut down client
            log.info("Quitting client");
            ftp.disconnect();

            log.info("Example complete");

        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.enterprisedt.net.ftp.FileTransferClient

public class Uploader
{
  public static void Upload(String src, int team) throws FTPException, IOException
  {
    FileTransferClient ftp = new FileTransferClient();
    ftp.setRemoteHost("10." + (team / 100) + "." + (team % 100) + ".2");
    ftp.connect();
    // (project)/PPC603gnu/projectname/Debug/projectname.out
    ftp.uploadFile(src, "/ni-rt/system/FRC_UserProgram.out");
    ftp.disconnect();
  }
View Full Code Here

Examples of com.enterprisedt.net.ftp.FileTransferClient

    ftp.uploadFile(src, "/ni-rt/system/FRC_UserProgram.out");
    ftp.disconnect();
  }
  public static void Delete(int team) throws FTPException, IOException
  {
    FileTransferClient ftp = new FileTransferClient();
    ftp.setRemoteHost("10." + (team / 100) + "." + (team % 100) + ".2");
    ftp.connect();
    // (project)/PPC603gnu/projectname/Debug/projectname.out
    ftp.deleteFile("/ni-rt/system/FRC_UserProgram.out");
    ftp.disconnect();
  }
View Full Code Here

Examples of de.fzj.unicore.uas.client.FileTransferClient

    if(source==null || source.getIsDirectory()){
      throw new IllegalStateException("Source="+source);
    }
   
    OutputStream os=targetStream!=null?targetStream:null;
    FileTransferClient ftc=null;
    try{
      String path=source.getPath();
      if(targetStream==null){
        if(localFile.isDirectory()){
          localFile=new File(localFile,getName(source.getPath()));
        }
        if(mode.equals(Mode.nooverwrite) && localFile.exists()){
          System.out.println("File exists and creation mode was set to 'nooverwrite'.");
          return;
        }
        System.out.println("Downloading remote file '"+sms.getUrl()+"#/"+path+"' -> "+localFile.getAbsolutePath());
        os=new FileOutputStream(localFile.getAbsolutePath(), mode.equals(Mode.append));
      }
     
      chosenProtocol=sms.findSupportedProtocol(preferredProtocols.toArray(new ProtocolType.Enum[preferredProtocols.size()]));
      Map<String,String>extraParameters=makeExtraParameters(chosenProtocol);
      ftc=sms.getExport(path,extraParameters,chosenProtocol);
      configure(ftc, extraParameters);
      System.out.println("DEB:File transfer URL : "+ftc.getUrl());
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable  && showProgress){
        long size=ftc.getSourceFileSize();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      long startTime=System.currentTimeMillis();
      if(isRange()){
        if(!(ftc instanceof SupportsPartialRead)){
          throw new Exception("Byte range is defined but protocol does not allow " +
              "partial read! Please choose a different protocol!");
        }
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        SupportsPartialRead pReader=(SupportsPartialRead)ftc;
        pReader.readPartial(startByte, endByte-startByte+1, os);
      }
      else{
        ftc.readAllData(os);
      }
//      if(p!=null){
//        p.finish();
//      }
      if(timing){
        long duration=System.currentTimeMillis()-startTime;
        double rate=(double)localFile.length()/(double)duration;
        System.out.println("Rate: " +rate+ " kB/sec.");
      }
      if(targetStream==null)copyProperties(source, localFile);
    }
    finally{
      try{
        if(targetStream==null && os!=null){
          os.close();
        }
      }catch(Exception ignored){}
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          System.out.println("Could not destroy the filetransfer client",e1);
        }
      }
    }
View Full Code Here

Examples of de.fzj.unicore.uas.client.FileTransferClient

   */
  private void uploadFile(File localFile, String remotePath, StorageClient sms, ProtocolType.Enum protocol,
      Map<String,String>extraParameters) throws Exception{
    long startTime=System.currentTimeMillis();
    FileInputStream is=null;
    FileTransferClient ftc=null;
    try{
      if(remotePath==null){
        remotePath="/"+localFile.getName();
      }
      else if(remotePath.endsWith("/")){
        remotePath+=localFile.getName();
      }
      System.out.println("Uploading local file '"+localFile.getAbsolutePath()+"' -> '"+sms.getUrl()+"#"+remotePath+"'");
      is=new FileInputStream(localFile.getAbsolutePath());
      boolean append=Mode.append.equals(mode);
      ftc=sms.getImport(remotePath, append, extraParameters, protocol);
      configure(ftc, extraParameters);
      if(append)ftc.setAppend(true);
      String url=ftc.getUrl();
      System.out.println("File transfer URL : "+url);
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable){
        long size=localFile.length();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      if(isRange()){
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        long skipped=0;
        while(skipped<startByte){
          skipped+=is.skip(startByte);
        }
        ftc.writeAllData(is, endByte-startByte+1);
       
      }else{
        ftc.writeAllData(is);
      }
      copyProperties(localFile, sms, remotePath);
     
//      if(ftc instanceof IMonitorable){
//        p.finish();
//      }
     
    }finally{
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          msg.error("Could not clean-up the filetransfer at <"+ftc.getUrl()+">",e1);
        }
      }
      try{ if(is!=null)is.close(); }catch(Exception ignored){}
View Full Code Here

Examples of de.fzj.unicore.uas.client.FileTransferClient

    if(source==null || source.getIsDirectory()){
      throw new IllegalStateException("Source="+source);
    }
   
    OutputStream os=targetStream!=null?targetStream:null;
    FileTransferClient ftc=null;
    try{
      String path=source.getPath();
      if(targetStream==null){
        if(localFile.isDirectory()){
          localFile=new File(localFile,getName(source.getPath()));
        }
        if(mode.equals(Mode.nooverwrite) && localFile.exists()){
          System.out.println("File exists and creation mode was set to 'nooverwrite'.");
          return;
        }
        System.out.println("Downloading remote file '"+sms.getUrl()+"#/"+path+"' -> "+localFile.getAbsolutePath());
        os=new FileOutputStream(localFile.getAbsolutePath(), mode.equals(Mode.append));
      }
     
      chosenProtocol=sms.findSupportedProtocol(preferredProtocols.toArray(new ProtocolType.Enum[preferredProtocols.size()]));
      Map<String,String>extraParameters=makeExtraParameters(chosenProtocol);
      ftc=sms.getExport(path,extraParameters,chosenProtocol);
      configure(ftc, extraParameters);
      System.out.println("DEB:File transfer URL : "+ftc.getUrl());
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable  && showProgress){
        long size=ftc.getSourceFileSize();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      long startTime=System.currentTimeMillis();
      if(isRange()){
        if(!(ftc instanceof SupportsPartialRead)){
          throw new Exception("Byte range is defined but protocol does not allow " +
              "partial read! Please choose a different protocol!");
        }
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        SupportsPartialRead pReader=(SupportsPartialRead)ftc;
        pReader.readPartial(startByte, endByte-startByte+1, os);
      }
      else{
        ftc.readAllData(os);
      }
//      if(p!=null){
//        p.finish();
//      }
      if(timing){
        long duration=System.currentTimeMillis()-startTime;
        double rate=(double)localFile.length()/(double)duration;
        System.out.println("Rate: " +rate+ " kB/sec.");
      }
      if(targetStream==null)copyProperties(source, localFile);
    }
    finally{
      try{
        if(targetStream==null && os!=null){
          os.close();
        }
      }catch(Exception ignored){}
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          System.out.println("Could not destroy the filetransfer client",e1);
        }
      }
    }
View Full Code Here

Examples of de.fzj.unicore.uas.client.FileTransferClient

   */
  private void uploadFile(File localFile, String remotePath, StorageClient sms, ProtocolType.Enum protocol,
      Map<String,String>extraParameters) throws Exception{
    long startTime=System.currentTimeMillis();
    FileInputStream is=null;
    FileTransferClient ftc=null;
    try{
      if(remotePath==null){
        remotePath="/"+localFile.getName();
      }
      else if(remotePath.endsWith("/")){
        remotePath+=localFile.getName();
      }
      System.out.println("Uploading local file '"+localFile.getAbsolutePath()+"' -> '"+sms.getUrl()+"#"+remotePath+"'");
      is=new FileInputStream(localFile.getAbsolutePath());
      boolean append=Mode.append.equals(mode);
      ftc=sms.getImport(remotePath, append, extraParameters, protocol);
      configure(ftc, extraParameters);
      if(append)ftc.setAppend(true);
      String url=ftc.getUrl();
      System.out.println("File transfer URL : "+url);
//      ProgressBar p=null;
      if(ftc instanceof IMonitorable){
        long size=localFile.length();
        if(isRange()){
          size=getRangeSize();
        }
//        p=new ProgressBar(localFile.getName(),size,msg);
//        ((IMonitorable) ftc).setProgressListener(p);
      }
      if(isRange()){
        System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
        long skipped=0;
        while(skipped<startByte){
          skipped+=is.skip(startByte);
        }
        ftc.writeAllData(is, endByte-startByte+1);
       
      }else{
        ftc.writeAllData(is);
      }
      copyProperties(localFile, sms, remotePath);
     
//      if(ftc instanceof IMonitorable){
//        p.finish();
//      }
     
    }finally{
      if(ftc!=null){
        try{
          ftc.destroy();
        }catch(Exception e1){
//          msg.error("Could not clean-up the filetransfer at <"+ftc.getUrl()+">",e1);
        }
      }
      try{ if(is!=null)is.close(); }catch(Exception ignored){}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.