Package org.apache.commons.net.ftp

Examples of org.apache.commons.net.ftp.FTPClient


   */
  private void open(boolean force) throws XException
  {
    if ((!mOpen) || force)
    {
      mFTPClient = new FTPClient();

      /*
       * Connect to the FTP Server
       */
      Configuration config = Configuration.getInstance();
View Full Code Here


    public FTPFile[] listFiles(String key, String relPath) throws IOException
    {
        try
        {
            updateLastAccessed();
          FTPClient client = getFtpClient();
          String dir = client.printWorkingDirectory();
          client.changeWorkingDirectory(relPath);
          FTPFile[] list = client.listFiles(key,null);
          client.changeWorkingDirectory(dir);
            return list;
        }
        catch (IOException e)
        {
            disconnect();
          FTPClient client = getFtpClient();
          String dir = client.printWorkingDirectory();
          client.changeWorkingDirectory(relPath);
          FTPFile[] list = client.listFiles(key,null);
          client.changeWorkingDirectory(dir);
            return list;
        }
        finally
        {
            updateLastAccessed();
View Full Code Here

    public InputStream retrieveFileStream(String relPath, long restartOffset) throws IOException
    {
        try
        {
            FTPClient client = getFtpClient();
            client.setRestartOffset(restartOffset);
            return new InFilter(client.retrieveFileStream(relPath));
        }
        catch (IOException e)
        {
            disconnect();

            FTPClient client = getFtpClient();
            client.setRestartOffset(restartOffset);
            return new InFilter(client.retrieveFileStream(relPath));
        }
    }
View Full Code Here

    this.localFile = localFile;
    this.fileType = fileType;
    this.userName = userName;
    this.password = password;
   
    ftpClient = new FTPClient();
    if (Externals.isDebugging)
      ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
  }
View Full Code Here

    }
  }

  private FTPClient Client() {
    if (objFTPClient == null) {
      objFTPClient = new FTPClient();
      FTPClientConfig conf = new FTPClientConfig();
      // conf.setServerLanguageCode("fr");
      // objFTPClient.configure(conf);
      /**
       * This listener is to write all commands and response from commands to system.out
View Full Code Here

        return res;
    }

    /** {@inheritDoc} */
    public boolean interrupt() {
        FTPClient client = savedClient;
        if (client != null) {
            savedClient = null;
            try {
                client.abort();
                client.disconnect();
            } catch (IOException ignored) {
            }
        }
        return client != null;
    }
View Full Code Here

        }
        InputStream input = null;
        OutputStream output = null;

        res.sampleStart();
        FTPClient ftp = new FTPClient();
        try {
            savedClient = ftp;
            final int port = getPortAsInt();
            if (port > 0){
                ftp.connect(getServer(),port);
            } else {
                ftp.connect(getServer());
            }
            res.latencyEnd();
            int reply = ftp.getReplyCode();
            if (FTPReply.isPositiveCompletion(reply))
            {
                if (ftp.login( getUsername(), getPassword())){
                    if (binaryTransfer) {
                        ftp.setFileType(FTP.BINARY_FILE_TYPE);
                    }
                    ftp.enterLocalPassiveMode();// should probably come from the setup dialog
                    boolean ftpOK=false;
                    if (isUpload()) {
                        String contents=getLocalFileContents();
                        if (contents.length() > 0){
                            byte bytes[] = contents.getBytes(); // TODO - charset?
                            input = new ByteArrayInputStream(bytes);
                            res.setBytes(bytes.length);
                        } else {
                            File infile = new File(local);
                            res.setBytes((int)infile.length());
                            input = new FileInputStream(infile);
                        }
                        ftpOK = ftp.storeFile(remote, input);
                    } else {
                        final boolean saveResponse = isSaveResponse();
                        ByteArrayOutputStream baos=null; // No need to close this
                        OutputStream target=null; // No need to close this
                        if (saveResponse){
                            baos  = new ByteArrayOutputStream();
                            target=baos;
                        }
                        if (local.length()>0){
                            output=new FileOutputStream(local);
                            if (target==null) {
                                target=output;
                            } else {
                                target = new TeeOutputStream(output,baos);
                            }
                        }
                        if (target == null){
                            target=new NullOutputStream();
                        }
                        input = ftp.retrieveFileStream(remote);
                        if (input == null){// Could not access file or other error
                            res.setResponseCode(Integer.toString(ftp.getReplyCode()));
                            res.setResponseMessage(ftp.getReplyString());
                        } else {
                            long bytes = IOUtils.copy(input,target);
                            ftpOK = bytes > 0;
                            if (saveResponse && baos != null){
                                res.setResponseData(baos.toByteArray());
                                if (!binaryTransfer) {
                                    res.setDataType(SampleResult.TEXT);
                                }
                            } else {
                                res.setBytes((int) bytes);
                            }
                        }
                    }

                    if (ftpOK) {
                        res.setResponseCodeOK();
                        res.setResponseMessageOK();
                        res.setSuccessful(true);
                    } else {
                        res.setResponseCode(Integer.toString(ftp.getReplyCode()));
                        res.setResponseMessage(ftp.getReplyString());
                    }
                } else {
                    res.setResponseCode(Integer.toString(ftp.getReplyCode()));
                    res.setResponseMessage(ftp.getReplyString());
                }
            } else {
                res.setResponseCode("501"); // TODO
                res.setResponseMessage("Could not connect");
                //res.setResponseCode(Integer.toString(ftp.getReplyCode()));
                res.setResponseMessage(ftp.getReplyString());
            }
        } catch (IOException ex) {
            res.setResponseCode("000"); // TODO
            res.setResponseMessage(ex.toString());
        } finally {
            savedClient = null;
            if (ftp.isConnected()) {
                try {
                    ftp.logout();
                } catch (IOException ignored) {
                }
                try {
                    ftp.disconnect();
                } catch (IOException ignored) {
                }
            }
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
View Full Code Here

        HIHOConf.ORACLE_EXTERNAL_TABLE_DIR);
    logger.debug("ip is " + ip);
    logger.debug("port, usr, password are " + portno + ", " + usr + ", "
        + pwd + "," + dir);
    if (ftpClient==null){
    ftpClient = new FTPClient();
    }
   
    ftpClient.connect(ip, Integer.parseInt(portno));
    logger.debug("Found connection");
    ftpClient.login(usr, pwd);
View Full Code Here

  @Test
  public final void testSetup() throws Exception {
    Mapper.Context context = mock(Mapper.Context.class);
    OracleLoadMapper mapper = new OracleLoadMapper();
    FTPClient ftpClient = mock(FTPClient.class);
    Configuration conf = new Configuration();
    String ip = "192.168.128.8";
    String portno = "21";
    String user = "nube";
    String password = "nube123";
View Full Code Here

  @Test
  public final void testMapper() throws Exception {
    Mapper.Context context = mock(Mapper.Context.class);
    OracleLoadMapper mapper = new OracleLoadMapper();
    FTPClient ftpClient = mock(FTPClient.class);
    FSDataInputStream val=mock(FSDataInputStream.class);
    Text key = new Text("key");
    mapper.setFtpClient(ftpClient);
    mapper.map(key, val, context);
    verify(ftpClient).appendFile("key", val);
View Full Code Here

TOP

Related Classes of org.apache.commons.net.ftp.FTPClient

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.