Example usage for org.apache.commons.net.ftp FTPCommand getCommand

List of usage examples for org.apache.commons.net.ftp FTPCommand getCommand

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPCommand getCommand.

Prototype

public static final String getCommand(int command) 

Source Link

Document

Retrieve the FTP protocol command string corresponding to a specified command code.

Usage

From source file:com.atomicleopard.thundr.ftp.commons.FTP.java

/***
 * Sends an FTP command to the server, waits for a reply and returns the
 * numerical response code.  After invocation, for more detailed
 * information, the actual reply text can be accessed by calling
 * {@link #getReplyString  getReplyString } or
 * {@link #getReplyStrings  getReplyStrings }.
 * <p>//from w  ww .j ava 2  s  . co  m
 * @param command  The FTPCommand constant corresponding to the FTP command
 *                 to send.
 * @param args The arguments to the FTP command.  If this parameter is
 *             set to null, then the command is sent with no argument.
 * @return The integer value of the FTP reply code returned by the server
 *         in response to the command.
 * @exception FTPConnectionClosedException
 *      If the FTP server prematurely closes the connection as a result
 *      of the client being idle or some other reason causing the server
 *      to send FTP reply code 421.  This exception may be caught either
 *      as an IOException or independently as itself.
 * @exception IOException  If an I/O error occurs while either sending the
 *      command or receiving the server reply.
 * @deprecated (3.3) Use {@link #sendCommand(FTPCmd, String)} instead
 ***/
@Deprecated
public int sendCommand(int command, String args) throws IOException {
    return sendCommand(FTPCommand.getCommand(command), args);
}

From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java

/**
 * Establishes a data connection with the FTP server, returning
 * a Socket for the connection if successful.  If a restart
 * offset has been set with {@link #setRestartOffset(long)},
 * a REST command is issued to the server with the offset as
 * an argument before establishing the data connection.  Active
 * mode connections also cause a local PORT command to be issued.
 * <p>//ww  w.ja v a2s. c  o m
 * @param command  The int representation of the FTP command to send.
 * @param arg The arguments to the FTP command.  If this parameter is
 *             set to null, then the command is sent with no argument.
 * @return A Socket corresponding to the established data connection.
 *         Null is returned if an FTP protocol error is reported at
 *         any point during the establishment and initialization of
 *         the connection.
 * @exception IOException  If an I/O error occurs while either sending a
 *      command to the server or receiving a reply from the server.
 * @deprecated (3.3) Use {@link #_openDataConnection_(FTPCmd, String)} instead
 */
@Deprecated
protected Socket _openDataConnection_(int command, String arg) throws IOException {
    return _openDataConnection_(FTPCommand.getCommand(command), arg);
}

From source file:nl.nn.adapterframework.ftp.FTPsClient.java

protected Socket _openDataConnection_(int cmdNr, String param) throws IOException {
    // if explicit FTPS, the socket connection is establisch unsecure
    if (session.getFtpType() == FtpSession.FTPS_EXPLICIT_SSL
            || session.getFtpType() == FtpSession.FTPS_EXPLICIT_TLS) {
        if (session.isProtp()) {
            // With Prot P the result is returned over a different port
            // .. send protp commands  

            sendCommand("PBSZ", "0");
            checkReply("PBSZ 0");
            sendCommand("PROT", "P");
            checkReply("PROT P");
            sendCommand("PASV");
            checkReply("PASV");

            // Parse the host and port name to which the result is send
            String reply = getReplyString();
            String line = reply.substring(reply.indexOf('(') + 1, reply.lastIndexOf(')'));
            String[] hostinfo = line.split(",");
            String host = hostinfo[0] + "." + hostinfo[1] + "." + hostinfo[2] + "." + hostinfo[3];
            int port = (Integer.parseInt(hostinfo[4]) << 8) + Integer.parseInt(hostinfo[5]);
            log.debug("channel from pasv reply=" + host + ":" + port);
            InetSocketAddress address = new InetSocketAddress(host, port);

            // connect to the result address
            Socket socket = new Socket();
            socket.connect(address);/*www.j  a v  a 2s.c  om*/
            socket.setSoTimeout(1000);
            host = socket.getInetAddress().getHostAddress();
            port = socket.getPort();
            log.debug("channel from socket=" + host + ":" + port);
            socket = socketFactory.createSocket(socket, host, port, true);

            String cmdLine = FTPCommand.getCommand(cmdNr);
            if (param != null) {
                cmdLine += ' ' + param;
            }
            // send the requested command (over the original socket)  <-- toch maar niet! GvB
            //            _sendCommand(cmdLine, _socket_.getOutputStream(), null);         
            sendCommand(cmdNr, param);

            // return the new socket for the reply 
            return socket;

        }
    }
    return super._openDataConnection_(cmdNr, param);
}