Examples of FTPClient


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

    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

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

    }
  }

  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

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

        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

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

        }
        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

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

        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

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

  @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

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

  @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

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

        }
    }
   
    public RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
        // configure ftp client
        FTPClient client = ftpClient;
       
        if (client == null) {
            // must use a new client if not explicit configured to use a custom client
            client = createFtpClient();
        }

        // set any endpoint configured timeouts
        if (getConfiguration().getConnectTimeout() > -1) {
            client.setConnectTimeout(getConfiguration().getConnectTimeout());
        }
        if (getConfiguration().getSoTimeout() > -1) {
            soTimeout = getConfiguration().getSoTimeout();
        }
        dataTimeout = getConfiguration().getTimeout();

        // then lookup ftp client parameters and set those
        if (ftpClientParameters != null) {
            Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);
            // setting soTimeout has to be done later on FTPClient (after it has connected)
            Object timeout = localParameters.remove("soTimeout");
            if (timeout != null) {
                soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
            }
            // and we want to keep data timeout so we can log it later
            timeout = localParameters.remove("dataTimeout");
            if (timeout != null) {
                dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
            }
            setProperties(client, localParameters);
        }
       
        if (ftpClientConfigParameters != null) {
            // client config is optional so create a new one if we have parameter for it
            if (ftpClientConfig == null) {
                ftpClientConfig = new FTPClientConfig();
            }
            Map<String, Object> localConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
            setProperties(ftpClientConfig, localConfigParameters);
        }

        if (dataTimeout > 0) {
            client.setDataTimeout(dataTimeout);
        }

        if (log.isDebugEnabled()) {
            log.debug("Created FTPClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}]: {}",
                    new Object[]{client.getConnectTimeout(), getSoTimeout(), dataTimeout, client});
        }

        FtpOperations operations = new FtpOperations(client, getFtpClientConfig());
        operations.setEndpoint(this);
        return operations;
View Full Code Here

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

        operations.setEndpoint(this);
        return operations;
    }

    protected FTPClient createFtpClient() throws Exception {
        return new FTPClient();
    }
View Full Code Here

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

    String dir = getOutputPath(job).toString();
    System.out.println("\n\ninside ftpoutputformat" + ip + " " + portno
        + " " + usr + " " + pwd + " " + dir);
    String keyValueSeparator = conf.get(
        "mapred.textoutputformat.separator", "\t");
    FTPClient f = new FTPClient();
    f.connect(ip, Integer.parseInt(portno));
    f.login(usr, pwd);
    f.changeWorkingDirectory(dir);
    f.setFileType(FTP.BINARY_FILE_TYPE);

    boolean isCompressed = getCompressOutput(job);
    CompressionCodec codec = null;
    String extension = "";
    if (isCompressed) {
      Class<? extends CompressionCodec> codecClass = getOutputCompressorClass(
          job, GzipCodec.class);
      codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass,
          conf);
      extension = codec.getDefaultExtension();
    }
    Path file = getDefaultWorkFile(job, extension);
    FileSystem fs = file.getFileSystem(conf);
    String filename = file.getName();
    if (!isCompressed) {
      // FSDataOutputStream fileOut = fs.create(file, false);
      OutputStream os = f.appendFileStream(filename);
      DataOutputStream fileOut = new DataOutputStream(os);
      return new FTPLineRecordWriter<K, V>(fileOut, new String(
          keyValueSeparator), f);

    } else {
      // FSDataOutputStream fileOut = fs.create(file, false);
      OutputStream os = f.appendFileStream(filename);
      DataOutputStream fileOut = new DataOutputStream(os);
      return new FTPLineRecordWriter<K, V>(new DataOutputStream(
          codec.createOutputStream(fileOut)), keyValueSeparator, f);
    }
  }
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.