Package com.enterprisedt.net.ftp

Examples of com.enterprisedt.net.ftp.FTPClient$DirectoryCallbackImpl


    File oFile;
    int iReaded;
    String sFullPath;
    boolean bRetVal = false;
    boolean bFTPSession = false;
    FTPClient oFTPC = null;
    String sCmd = null;
    InputStream oStdOut;
    byte verbose[] = new byte[256];

    if (DebugFile.trace) {
      DebugFile.writeln("Begin FileSystem.rmdir(" + sFullURI + ")");
      DebugFile.incIdent();
    }

    if (sFullURI.startsWith("file://")) {
      sFullPath = sFullURI.substring(7);
      if (sFullPath.endsWith(SLASH)) sFullPath = sFullPath.substring(0, sFullPath.length()-SLASH.length());
      oFile = new File(sFullPath);

      if (DebugFile.trace) DebugFile.writeln(sFullPath + " is a directory");

      switch (OS) {
          case OS_PUREJAVA:
            bRetVal = oFile.delete();
            break;
          case OS_UNIX:
            sCmd = "rm -rf \"" + sFullPath + "\"";
            break;
          case OS_WINDOWS:
            sCmd = "DEL /F /S /Q \"" + sFullPath + "\"";
            break;
      } // end switch()

      if (null!=sCmd) {
          if (DebugFile.trace) {
            DebugFile.writeln("Runtime.exec(" + sCmd + ")");
            oStdOut = oRunner.exec(sCmd).getInputStream();
            iReaded = oStdOut.read(verbose, 0, 255);
            oStdOut.close();
            if (iReaded > 0) {
              DebugFile.writeln(new String(verbose, iReaded));
              bRetVal = false;
            }
            else
              bRetVal = true;
          }
          else {
            oRunner.exec(sCmd);
            bRetVal = true;
          }
      } // fi (sCmd)

      if (oFile.exists()) bRetVal = false;

      oFile = null;
    }

    else if (sFullURI.startsWith("ftp://")) {

      splitURI(sFullURI);

      try {
        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");

        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("oFTPC.login(" + sUsr + ", ...);");

        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        sFullPath = Gadgets.chomp(sPath, '/') + sFile;

        String[] aSubDirs = listDirsFTP(oFTPC, sFullPath);

        for (int d = 0; d < aSubDirs.length; d++) {
          delete (Gadgets.chomp(sFullURI, '/') + aSubDirs[d]);
        }

        String[] aFiles = listFilesFTP(oFTPC, sFullPath);

        for (int f=0; f<aFiles.length; f++) {
          if (DebugFile.trace) DebugFile.writeln("FTPClient.delete(" + Gadgets.chomp(sPath,'/') + Gadgets.chomp(sFile,'/') + aFiles[f] + ")");

          oFTPC.delete (Gadgets.chomp(sPath,'/') + Gadgets.chomp(sFile,'/') + aFiles[f]);
        }

        if (DebugFile.trace) DebugFile.writeln("FTPClient.rmdir(" + sFullPath + ")");

        oFTPC.rmdir(sFullPath);

        bRetVal = true;
      } catch (FTPException ftpe) {
        bRetVal = false;
        throw new IOException(ftpe.getMessage());
      }
      catch (Exception xcpt) {
        bRetVal = false;
        throw new IOException(xcpt.getMessage());
      }
      finally {
        try { if (bFTPSession) oFTPC.quit(); } catch (Exception xcpt) { }
      }
    }
    // fi(sFullURI.startsWith(...))

    if (DebugFile.trace) {
View Full Code Here


  public boolean delete (String sFullURI) throws IOException {
    File oFile;
    String sFullPath;
    boolean bRetVal = false;
    boolean bFTPSession = false;
    FTPClient oFTPC = null;
    String sCmd = null;
    byte verbose[] = new byte[256];

    if (DebugFile.trace) {
      DebugFile.writeln("Begin FileSystem.delete(" + sFullURI + ")");
      DebugFile.incIdent();
      switch (OS) {
        case OS_PUREJAVA:
          DebugFile.writeln("OS mode is Pure Java");
          break;
        case OS_UNIX:
          DebugFile.writeln("OS mode is Unix");
          break;
        case OS_WINDOWS:
          DebugFile.writeln("OS mode is Windows");
          break;
      }
    }

    // Codigo a ejecutar por el protocolo de ficheros locales
    if (sFullURI.startsWith("file://")) {
      sFullPath = sFullURI.substring(7);
      if (sFullPath.endsWith(SLASH)) sFullPath = sFullPath.substring(0, sFullPath.length()-SLASH.length());
      oFile = new File(sFullPath);

      if (oFile.isFile()) {
        if (DebugFile.trace) DebugFile.writeln(sFullPath + " is a file");
        bRetVal = oFile.delete();
      }
      else {
        bRetVal = rmdir(sFullURI);
      } // fi (isFile())
      oFile = null;
    }
    // Codigo a ejecutar por el protocolo FTP
    else if (sFullURI.startsWith("ftp://")) {

      splitURI(sFullURI);

      try {
        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");

        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("oFTPC.login(" + sUsr + ", ...);");

        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        sFullPath = Gadgets.chomp(sPath,'/') + sFile;

        if (isDirectoryFTP(oFTPC, sFullPath)) {
          oFTPC.quit();
          bFTPSession = false;
          rmdir (sFullURI);
        }
        else {
          oFTPC.delete(sFullPath);
        }

        bRetVal = true;
      } catch (FTPException ftpe) {
        bRetVal = false;
        throw new IOException(ftpe.getMessage());
      }
      catch (Exception xcpt) {
        bRetVal = false;
        throw new IOException(xcpt.getMessage());
      }
      finally {
        try { if (bFTPSession) oFTPC.quit(); } catch (Exception xcpt) { }
      }
    }
    // fi(sFullURI.startsWith(...))

    if (DebugFile.trace) {
View Full Code Here

  private boolean moveFTPToFTP (String sSourceURI, String sTargetURI) throws FTPException, IOException {
    boolean bRetVal = true;
    String sSourceHost, sTargetHost, sSourcePath, sTargetPath, sSourceFile, sTargetFile;
    FTPWorkerThread oReader,oWriter;
    FTPClient oFTPC;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin FileSystem.moveFTPToFTP(" + sSourceURI + "," + sTargetURI + ")");
      DebugFile.incIdent();
    }

    splitURI(sSourceURI);
    sSourceHost = sHost;
    sSourcePath = sPath;
    if (!sSourcePath.endsWith("/")) sSourcePath+="/";
    sSourceFile = sFile;

    splitURI(sTargetURI);
    sTargetHost = sHost;
    sTargetPath = sPath;
    if (!sTargetPath.endsWith("/")) sTargetPath+="/";
    sTargetFile = sFile;

    if (sSourceHost.equals(sTargetHost)) {
      if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sTargetHost + ")");

      oFTPC = new FTPClient(sTargetHost);
      oFTPC.login(user(), password());

      if (DebugFile.trace) DebugFile.writeln("FTPClient.rename(" + sSourcePath + sSourceFile + "," + sTargetPath + sTargetFile + ")");

      oFTPC.rename(sSourcePath + sSourceFile, sTargetPath + sTargetFile);
      oFTPC.quit();
    }
    else {

      oReader = new FTPWorkerThread(sSourceHost, sUsr, sPwd);
      oWriter = new FTPWorkerThread(sTargetHost, sUsr, sPwd);
View Full Code Here

      DebugFile.writeln("Begin FileSystem.mkdirs(" + sFullURI + ")");
      DebugFile.incIdent();
    }

    File oFile;
    FTPClient oFTPC = null;
    boolean bRetVal = false;
    String sFullPath = sFullURI.substring(7);

    // Assume file protocol by default
    if (!sFullURI.startsWith("file://") && !sFullURI.startsWith("ftp://"))
      sFullURI = "file://" + sFullURI;

    if (sFullURI.startsWith("file://")) {
      switch (OS) {
        case OS_PUREJAVA:
          oFile = new File(sFullPath);
          if (DebugFile.trace) DebugFile.writeln("File.mkdirs(" + sFullPath + ")");
          bRetVal = oFile.mkdirs();
          oFile = null;
          break;
        case OS_UNIX:
          if (DebugFile.trace) DebugFile.writeln("mkdir -p \"" + sFullPath + "\"");
          sCmd = "mkdir -p \"" + sFullPath + "\"";
          oRunner.exec(sCmd);
          break;
        case OS_WINDOWS:
          if (DebugFile.trace) DebugFile.writeln("md \"" + sFullPath + "\"");
          sCmd = "md \"" + sFullPath + "\"";
          oRunner.exec(sCmd);
          break;
      }
    }
    else if (sFullURI.startsWith("ftp://")) {
      if (!sFullURI.endsWith("/")) sFullURI += "/";
      splitURI(sFullURI);

      try {
        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
        oFTPC.login(sUsr, sPwd);
        bFTPSession = true;

        if (DebugFile.trace) DebugFile.writeln("FileSystem.mkdirsFTP(" + sPath + ")");

        mkdirsFTP(oFTPC, sPath);
        bRetVal = true;
      }
      catch (FTPException ftpe) {
        throw new IOException(ftpe.getMessage());
      }
      finally {
        if (bFTPSession) oFTPC.quit();
      }
    } // fi(sFullURI.startsWith(...))

    if (DebugFile.trace) {
      DebugFile.decIdent();
View Full Code Here

        }
      } // fi (user is anonymous)
    }
    else if (sLower.startsWith("ftp://")) {

      FTPClient oFTPC = null;
      boolean bFTPSession = false;

      splitURI (sFilePath);

      try {

        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
        oFTPC.chdir(sPath);

        ByteArrayOutputStream oStrm = new ByteArrayOutputStream();

        oFTPC.setType(FTPTransferType.BINARY);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.get(" + sPath + sFile + "," + sFile + ",false)");
        oFTPC.get(oStrm, sFile);

        aRetVal = oStrm.toByteArray();

        oStrm.close();
      } catch (FTPException ftpe) {
        throw new FTPException(ftpe.getMessage());
      }
      finally {
        if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
        if (bFTPSession) oFTPC.quit();
      }

    }
    else {
View Full Code Here

        }
    } // fi
    }
    else if (sLower.startsWith("ftp://")) {

      FTPClient oFTPC = null;
      boolean bFTPSession = false;

      splitURI (sFilePath);

      try {

        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
        oFTPC.chdir(sPath);

        ByteArrayOutputStream oStrm = new ByteArrayOutputStream();

        oFTPC.setType(FTPTransferType.BINARY);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.get(" + sPath + sFile + "," + sFile + ",false)");
        oFTPC.get(oStrm, sFile);

        sRetVal = oStrm.toString(sEncoding);

        oStrm.close();
      } catch (FTPException ftpe) {
        throw new FTPException(ftpe.getMessage());
      }
      finally {
        if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
        try { if (bFTPSession) oFTPC.quit(); } catch (Exception ignore) { }
      }
    }
    else {

      File oFile = new File(sFilePath);
View Full Code Here

    if (sLower.startsWith("file://")) sFilePath = sFilePath.substring(7);

    if (sLower.startsWith("ftp://")) {

      FTPClient oFTPC = null;
      boolean bFTPSession = false;

      splitURI(sFilePath);

      try {

        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," +
                                               sPwd + ")");
        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
        oFTPC.chdir(sPath);

        oFTPC.setType(FTPTransferType.BINARY);
        if (DebugFile.trace) DebugFile.writeln("FTPClient.put(byte[], " + sFile + ")");
        oFTPC.put(sText.getBytes(sEncoding), sFile);
      }
      catch (FTPException ftpe) {
        throw new IOException(ftpe.getMessage());
      }
      finally {
        if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
        try { if (bFTPSession) oFTPC.quit(); } catch (Exception ignore) { }
      }
    }
    else {
      FileOutputStream oOutStrm = new FileOutputStream(sFilePath);
View Full Code Here

    if (sLower.startsWith("file://")) sFilePath = sFilePath.substring(7);

    if (sLower.startsWith("ftp://")) {

      FTPClient oFTPC = null;
      boolean bFTPSession = false;

      splitURI(sFilePath);

      try {

        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);

        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," +
                                               sPwd + ")");
        oFTPC.login(sUsr, sPwd);

        bFTPSession = true;

        if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
        oFTPC.chdir(sPath);

        oFTPC.setType(FTPTransferType.BINARY);
        if (DebugFile.trace) DebugFile.writeln("FTPClient.put(byte[], " + sFile + ")");
        oFTPC.put(aBytes, sFile);
      }
      catch (FTPException ftpe) {
        throw new IOException(ftpe.getMessage());
      }
      finally {
        if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
        try { if (bFTPSession) oFTPC.quit(); } catch (Exception ignore) { }
      }
    }
    else {
      FileOutputStream oOutStrm = new FileOutputStream(sFilePath);
      oOutStrm.write(aBytes);
View Full Code Here

    FTPFileSystem(final FTPFSDevice device, final FTPFileSystemType type) {
        this.type = type;
        this.client = AccessController.doPrivileged(new PrivilegedAction<FTPClient>() {
            @Override
            public FTPClient run() {
                return new FTPClient();
            }
        });
        this.device = device;
        device.addListener(new DeviceListener() {
            public void deviceStarted(Device device) {
View Full Code Here

                          "com.sun.star.frame.Desktop",
                          xComponentContext));
         
          //System.out.println("Loading document "+url);
                 
          FTPClient ftp = new FTPClient();
          if(!host.equals("localhost")){
            //ftp connexion           
            ftp.setRemoteHost(host);
            ftp.connect();
            ftp.login(ftpuser, ftpPasswd);
            ftp.setConnectMode(FTPConnectMode.PASV);
            ftp.setType(FTPTransferType.BINARY);
                  try{
                    ftp.mkdir(remoteFolder);
                  }catch(Exception e){}
                  ftp.chdir(remoteFolder);
                  ftp.put(url,"presentation.ppt");                 
                  url = remoteFolderFullPath+"/"+remoteFolder+"/presentation.ppt";
                 
                 
          }
         
          PropertyValue[] loadProps = new PropertyValue[2];
          loadProps[0] = new PropertyValue();
            loadProps[0].Name = "Hidden";
            loadProps[0].Value = new Boolean(true);
           
          // open the document
          XComponent component = xcomponentloader
              .loadComponentFromURL(url,
                  "_blank", 0, loadProps);
         
             
          //System.out.println("Document Opened");
         
          // filter
          loadProps = new PropertyValue[4];
         
          // type of image
          loadProps[0] = new PropertyValue();
          loadProps[0].Name = "MediaType";
          loadProps[0].Value = "image/png";
         
          // Height and width
          PropertyValue[] filterDatas = new PropertyValue[4];
          for(int i = 0; i<4 ; i++){
            filterDatas[i] = new PropertyValue();
          }
         
          filterDatas[0].Name = "PixelWidth";
          filterDatas[0].Value = new Integer(width);
          filterDatas[1].Name = "PixelHeight";
          filterDatas[1].Value = new Integer(height);
          filterDatas[2].Name = "LogicalWidth";
          filterDatas[2].Value = new Integer(2000);
          filterDatas[3].Name = "LogicalHeight";
          filterDatas[3].Value = new Integer(2000);
         
         
          XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
              .queryInterface(XDrawPagesSupplier.class, component);
          //System.out.println(pagesSupplier.toString());       
          XDrawPages pages = pagesSupplier.getDrawPages();
          int nbPages = pages.getCount();
               
         
          for (int i = 0; i < nbPages; i++) {
                     
            XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(
                com.sun.star.drawing.XDrawPage.class, pages
                    .getByIndex(i));
           
            XNamed xPageName = (XNamed)UnoRuntime.queryInterface(XNamed.class,page);
           
            xPageName.setName("slide"+(i+1));
            //if(!xPageName.getName().equals("slide"+(i+1)) && !xPageName.getName().equals("page"+(i+1)))
              //xPageName.setName((i+1)+"-"+xPageName.getName());
            Object GraphicExportFilter = xMultiComponentFactory
                .createInstanceWithContext(
                    "com.sun.star.drawing.GraphicExportFilter",
                    xComponentContext);
            XExporter xExporter = (XExporter) UnoRuntime
                .queryInterface(XExporter.class,
                    GraphicExportFilter);

            XComponent xComp = (XComponent) UnoRuntime
                .queryInterface(XComponent.class, page);

            xExporter.setSourceDocument(xComp);
            loadProps[1] = new PropertyValue();
            loadProps[1].Name = "URL";
            loadProps[1].Value = remoteFolderFullPath+remoteFolder+"/"+xPageName.getName()+".png";
            loadProps[2] = new PropertyValue();
            loadProps[2].Name = "FilterData";
            loadProps[2].Value = filterDatas;
            loadProps[3] = new PropertyValue();
            loadProps[3].Name = "Quality";
            loadProps[3].Value = new Integer(100);
           
            XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);

            xFilter.filter(loadProps);
            System.out.println(xPageName.getName()+".png");

            //System.out.println("Page saved to url "+loadProps[1].Value);
           
          }
         
          if(!host.equals("localhost")){
            String[] files = ftp.dir();
                  for (int i = 0; i < files.length; i++){
                    //System.out.println("Transfer of "+files[i]+ "to "+destinationFolder+"/"+files[i]);
                    if(!files[i].equals("presentation.ppt"))
                      ftp.get(destinationFolder+"/"+files[i],files[i]);
                    ftp.delete(files[i]);
                  }
            ftp.chdir("..");
            ftp.rmdir(remoteFolder);
            ftp.quit();
          }
         
          //System.out.println("Closing Document");
          component.dispose();
          //System.out.println("Document close");
View Full Code Here

TOP

Related Classes of com.enterprisedt.net.ftp.FTPClient$DirectoryCallbackImpl

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.