Examples of FTPClient


Examples of com.enterprisedt.net.ftp.FTPClient

  if (sSourceURI.startsWith("file://")) {
    bExists = new File(sSourceURI.substring(7)).exists();   
  } else if (sSourceURI.startsWith("ftp://")) {
      boolean bFTPSession = false;
      FTPClient oFTPC = null;
      splitURI(sSourceURI);
    String[] aFiles = null;
    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.dir(" + sPath + ")");
        aFiles = oFTPC.dir(sPath);
      oFTPC.quit();
    } catch (FTPException ftpe) {
      throw new IOException(ftpe.getMessage());
    }
    if (aFiles!=null) {
      int nFiles = aFiles.length;
View Full Code Here

Examples of com.enterprisedt.net.ftp.FTPClient

    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

Examples of com.enterprisedt.net.ftp.FTPClient

  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

Examples of com.enterprisedt.net.ftp.FTPClient

  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

Examples of com.enterprisedt.net.ftp.FTPClient

      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

Examples of com.enterprisedt.net.ftp.FTPClient

        }
      } // 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

Examples of com.enterprisedt.net.ftp.FTPClient

        }
    } // 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

Examples of com.enterprisedt.net.ftp.FTPClient

    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

Examples of com.enterprisedt.net.ftp.FTPClient

    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

Examples of com.oroinc.net.ftp.FTPClient

    /** Runs the task.  */
    public void execute()
         throws BuildException {
        checkConfiguration();

        FTPClient ftp = null;

        try {
            log("Opening FTP connection to " + server, Project.MSG_VERBOSE);

            ftp = new FTPClient();

            ftp.connect(server, port);
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                throw new BuildException("FTP connection failed: "
                     + ftp.getReplyString());
            }

            log("connected", Project.MSG_VERBOSE);
            log("logging in to FTP server", Project.MSG_VERBOSE);

            if (!ftp.login(userid, password)) {
                throw new BuildException("Could not login to FTP server");
            }

            log("login succeeded", Project.MSG_VERBOSE);

            if (binary) {
                ftp.setFileType(com.oroinc.net.ftp.FTP.IMAGE_FILE_TYPE);
                if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                    throw new BuildException("could not set transfer type: " +
                        ftp.getReplyString());
                }
            }

            if (passive) {
                log("entering passive mode", Project.MSG_VERBOSE);
                ftp.enterLocalPassiveMode();
                if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                    throw new BuildException("could not enter into passive "
                         + "mode: " +
                        ftp.getReplyString());
                }
            }

            // For a unix ftp server you can set the default mask for all files
            // created.

            if (umask != null) {
                doSiteCommand(ftp, "umask " + umask);
            }

            // If the action is MK_DIR, then the specified remote
            // directory is the directory to create.

            if (action == MK_DIR) {
                makeRemoteDir(ftp, remotedir);
            } else {
                if (remotedir != null) {
                    log("changing the remote directory", Project.MSG_VERBOSE);
                    ftp.changeWorkingDirectory(remotedir);
                    if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                        throw new BuildException("could not change remote "
                             + "directory: " +
                            ftp.getReplyString());
                    }
                }
                log(ACTION_STRS[action] + " files");
                transferFiles(ftp);
            }

        } catch (IOException ex) {
            throw new BuildException("error during FTP transfer: " + ex);
        } finally {
            if (ftp != null && ftp.isConnected()) {
                try {
                    log("disconnecting", Project.MSG_VERBOSE);
                    ftp.logout();
                    ftp.disconnect();
                } catch (IOException ex) {
                    // ignore it
                }
            }
        }
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.