Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

In this page you can find the example usage for java.io IOException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:examples.ftp.java

public static final void main(String[] args) {
    int base = 0;
    boolean storeFile = false, binaryTransfer = false, error = false;
    String server, username, password, remote, local;
    FTPClient ftp;/*from  ww  w. j  a va 2s  .  c  o  m*/

    for (base = 0; base < args.length; base++) {
        if (args[base].startsWith("-s"))
            storeFile = true;
        else if (args[base].startsWith("-b"))
            binaryTransfer = true;
        else
            break;
    }

    if ((args.length - base) != 5) {
        System.err.println(USAGE);
        System.exit(1);
    }

    server = args[base++];
    username = args[base++];
    password = args[base++];
    remote = args[base++];
    local = args[base];

    ftp = new FTPClient();
    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

    try {
        int reply;
        ftp.connect(server);
        System.out.println("Connected to " + server + ".");

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }
    } catch (IOException e) {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    __main: try {
        if (!ftp.login(username, password)) {
            ftp.logout();
            error = true;
            break __main;
        }

        System.out.println("Remote system is " + ftp.getSystemName());

        if (binaryTransfer)
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        // Use passive mode as default because most of us are
        // behind firewalls these days.
        ftp.enterLocalPassiveMode();

        if (storeFile) {
            InputStream input;

            input = new FileInputStream(local);

            ftp.storeFile(remote, input);

            input.close();
        } else {
            OutputStream output;

            output = new FileOutputStream(local);

            ftp.retrieveFile(remote, output);

            output.close();
        }

        ftp.logout();
    } catch (FTPConnectionClosedException e) {
        error = true;
        System.err.println("Server closed connection.");
        e.printStackTrace();
    } catch (IOException e) {
        error = true;
        e.printStackTrace();
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
    }

    System.exit(error ? 1 : 0);
}

From source file:com.bluemarsh.jswat.console.Main.java

/**
 * Kicks off the application.//  www.j a v a  2  s  .c o m
 *
 * @param  args  the command line arguments.
 */
public static void main(String[] args) {
    //
    // An attempt was made early on to use the Console class in java.io,
    // but that is not designed to handle asynchronous output from
    // multiple threads, so we just use the usual System.out for output
    // and System.in for input. Note that automatic flushing is used to
    // ensure output is shown in a timely fashion.
    //

    //
    // Where console mode seems to work:
    // - bash
    // - emacs
    //
    // Where console mode does not seem to work:
    // - NetBeans: output from event listeners is never shown and the
    //   cursor sometimes lags behind the output
    //

    // Turn on flushing so printing the prompt will flush
    // all buffered output generated from other threads.
    PrintWriter output = new PrintWriter(System.out, true);

    // Make sure we have the JPDA classes.
    try {
        Bootstrap.virtualMachineManager();
    } catch (NoClassDefFoundError ncdfe) {
        output.println(NbBundle.getMessage(Main.class, "MSG_Main_NoJPDA"));
        System.exit(1);
    }

    // Ensure we can create the user directory by requesting the
    // platform service. Simply asking for it has the desired effect.
    PlatformProvider.getPlatformService();

    // Define the logging configuration.
    LogManager manager = LogManager.getLogManager();
    InputStream is = Main.class.getResourceAsStream("logging.properties");
    try {
        manager.readConfiguration(is);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.exit(1);
    }

    // Print out some useful debugging information.
    logSystemDetails();

    // Add a shutdown hook to make sure we exit cleanly.
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            // Save the command aliases.
            CommandParser parser = CommandProvider.getCommandParser();
            parser.saveSettings();
            // Save the runtimes to persistent storage.
            RuntimeManager rm = RuntimeProvider.getRuntimeManager();
            rm.saveRuntimes();
            // Save the sessions to persistent storage and have them
            // close down in preparation to exit.
            SessionManager sm = SessionProvider.getSessionManager();
            sm.saveSessions(true);
        }
    }));

    // Initialize the command parser and load the aliases.
    CommandParser parser = CommandProvider.getCommandParser();
    parser.loadSettings();
    parser.setOutput(output);

    // Create an OutputAdapter to display debuggee output.
    OutputAdapter adapter = new OutputAdapter(output);
    SessionManager sessionMgr = SessionProvider.getSessionManager();
    sessionMgr.addSessionManagerListener(adapter);
    // Create a SessionWatcher to monitor the session status.
    SessionWatcher swatcher = new SessionWatcher();
    sessionMgr.addSessionManagerListener(swatcher);
    // Create a BreakpointWatcher to monitor the breakpoints.
    BreakpointWatcher bwatcher = new BreakpointWatcher();
    sessionMgr.addSessionManagerListener(bwatcher);

    // Add the watchers and adapters to the open sessions.
    Iterator<Session> iter = sessionMgr.iterateSessions();
    while (iter.hasNext()) {
        Session s = iter.next();
        s.addSessionListener(adapter);
        s.addSessionListener(swatcher);
    }

    // Find and run the RC file.
    try {
        runStartupFile(parser, output);
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, null, ioe);
    }

    // Process command line arguments.
    try {
        processArguments(args);
    } catch (ParseException pe) {
        // Report the problem and keep going.
        System.err.println("Option parsing failed: " + pe.getMessage());
        logger.log(Level.SEVERE, null, pe);
    }

    // Display a helpful greeting.
    output.println(NbBundle.getMessage(Main.class, "MSG_Main_Welcome"));
    if (jdbEmulationMode) {
        output.println(NbBundle.getMessage(Main.class, "MSG_Main_Jdb_Emulation"));
    }

    // Enter the main loop of processing user input.
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        // Keep the prompt format identical to jdb for compatibility
        // with emacs and other possible wrappers.
        output.print("> ");
        output.flush();
        try {
            String command = input.readLine();
            // A null value indicates end of stream.
            if (command != null) {
                performCommand(output, parser, command);
            }
            // Sleep briefly to give the event processing threads,
            // and the automatic output flushing, a chance to catch
            // up before printing the input prompt again.
            Thread.sleep(250);
        } catch (InterruptedException ie) {
            logger.log(Level.WARNING, null, ie);
        } catch (IOException ioe) {
            logger.log(Level.SEVERE, null, ioe);
            output.println(NbBundle.getMessage(Main.class, "ERR_Main_IOError", ioe));
        } catch (Exception x) {
            // Don't ever let an internal bug (e.g. in the command parser)
            // hork the console, as it really irritates people.
            logger.log(Level.SEVERE, null, x);
            output.println(NbBundle.getMessage(Main.class, "ERR_Main_Exception", x));
        }
    }
}

From source file:net.minecraftforge.fml.common.asm.transformers.AccessTransformer.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: AccessTransformer <JarPath> <MapFile> [MapFile2]... ");
        System.exit(1);//  w w w .  j a v a  2 s.c  o m
    }

    boolean hasTransformer = false;
    AccessTransformer[] trans = new AccessTransformer[args.length - 1];
    for (int x = 1; x < args.length; x++) {
        try {
            trans[x - 1] = new AccessTransformer(args[x]);
            hasTransformer = true;
        } catch (IOException e) {
            System.out.println("Could not read Transformer Map: " + args[x]);
            e.printStackTrace();
        }
    }

    if (!hasTransformer) {
        System.out.println("Could not find a valid transformer to perform");
        System.exit(1);
    }

    File orig = new File(args[0]);
    File temp = new File(args[0] + ".ATBack");
    if (!orig.exists() && !temp.exists()) {
        System.out.println("Could not find target jar: " + orig);
        System.exit(1);
    }

    if (!orig.renameTo(temp)) {
        System.out.println("Could not rename file: " + orig + " -> " + temp);
        System.exit(1);
    }

    try {
        processJar(temp, orig, trans);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    if (!temp.delete()) {
        System.out.println("Could not delete temp file: " + temp);
    }
}

From source file:aplicacion.sistema.version.logic.ftp.java

public static final void main(String[] args) {
    int base = 0;
    boolean storeFile = false, binaryTransfer = false, error = false;
    String server, username, password, remote, local;
    server = "gisbertrepuestos.com.ar";
    username = "gisbertrepuestos.com.ar";
    password = "ipsilon@1982";
    remote = "beta/beta-patch.msp";
    local = "c:/beta-patch-from-ftp.msp";
    FTPClient ftp;/*from  w ww  . j  a  v a  2 s  .  c  om*/
    /*
    for (base = 0; base < args.length; base++)
    {
    if (args[base].startsWith("-s"))
        storeFile = true;
    else if (args[base].startsWith("-b"))
        binaryTransfer = true;
    else
        break;
    }
            
    if ((args.length - base) != 5)
    {
    System.err.println(USAGE);
    System.exit(1);
    }
            
    server = args[base++];
    username = args[base++];
    password = args[base++];
    remote = args[base++];
    local = args[base];
    */
    ftp = new FTPClient();
    ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

    try {
        int reply;
        ftp.connect(server);
        System.out.println("Connected to " + server + ".");

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }
    } catch (IOException e) {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    __main: try {
        if (!ftp.login(username, password)) {
            ftp.logout();
            error = true;
            break __main;
        }

        System.out.println("Remote system is " + ftp.getSystemName());

        if (binaryTransfer)
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        // Use passive mode as default because most of us are
        // behind firewalls these days.
        ftp.enterLocalPassiveMode();

        if (storeFile) {
            InputStream input;

            input = new FileInputStream(local);

            ftp.storeFile(remote, input);

            input.close();
        } else {
            OutputStream output;

            output = new FileOutputStream(local);

            ftp.retrieveFile(remote, output);

            output.close();
        }

        ftp.logout();
    } catch (FTPConnectionClosedException e) {
        error = true;
        System.err.println("Server closed connection.");
        e.printStackTrace();
    } catch (IOException e) {
        error = true;
        e.printStackTrace();
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
    }

    System.exit(error ? 1 : 0);
}

From source file:examples.ftp.FTPSExample.java

public static final void main(String[] args) throws NoSuchAlgorithmException {
    int base = 0;
    boolean storeFile = false, binaryTransfer = false, error = false;
    String server, username, password, remote, local;
    String protocol = "SSL"; // SSL/TLS
    FTPSClient ftps;//from w  w  w.  j a v  a2s  .co  m

    for (base = 0; base < args.length; base++) {
        if (args[base].startsWith("-s"))
            storeFile = true;
        else if (args[base].startsWith("-b"))
            binaryTransfer = true;
        else
            break;
    }

    if ((args.length - base) != 5) {
        System.err.println(USAGE);
        System.exit(1);
    }

    server = args[base++];
    username = args[base++];
    password = args[base++];
    remote = args[base++];
    local = args[base];

    ftps = new FTPSClient(protocol);

    ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

    try {
        int reply;

        ftps.connect(server);
        System.out.println("Connected to " + server + ".");

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftps.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftps.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }
    } catch (IOException e) {
        if (ftps.isConnected()) {
            try {
                ftps.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
        System.err.println("Could not connect to server.");
        e.printStackTrace();
        System.exit(1);
    }

    __main: try {
        ftps.setBufferSize(1000);

        if (!ftps.login(username, password)) {
            ftps.logout();
            error = true;
            break __main;
        }

        System.out.println("Remote system is " + ftps.getSystemName());

        if (binaryTransfer)
            ftps.setFileType(FTP.BINARY_FILE_TYPE);

        // Use passive mode as default because most of us are
        // behind firewalls these days.
        ftps.enterLocalPassiveMode();

        if (storeFile) {
            InputStream input;

            input = new FileInputStream(local);

            ftps.storeFile(remote, input);

            input.close();
        } else {
            OutputStream output;

            output = new FileOutputStream(local);

            ftps.retrieveFile(remote, output);

            output.close();
        }

        ftps.logout();
    } catch (FTPConnectionClosedException e) {
        error = true;
        System.err.println("Server closed connection.");
        e.printStackTrace();
    } catch (IOException e) {
        error = true;
        e.printStackTrace();
    } finally {
        if (ftps.isConnected()) {
            try {
                ftps.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
    }

    System.exit(error ? 1 : 0);
}

From source file:com.imaginary.home.cloud.api.call.LocationCall.java

static public void main(String... args) throws Exception {
    if (args.length < 1) {
        System.err.println("You must specify an action");
        System.exit(-1);//from  w  w  w  . ja v  a2 s  .c o  m
        return;
    }
    String action = args[0];

    if (action.equalsIgnoreCase("initializePairing")) {
        if (args.length < 5) {
            System.err.println("You must specify a location ID");
            System.exit(-2);
            return;
        }
        String endpoint = args[1];
        String locationId = args[2];
        String apiKeyId = args[3];
        String apiKeySecret = args[4];

        HashMap<String, Object> act = new HashMap<String, Object>();

        act.put("action", "initializePairing");

        HttpParams params = new BasicHttpParams();

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        //noinspection deprecation
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUserAgent(params, "Imaginary Home");

        HttpClient client = new DefaultHttpClient(params);

        HttpPut method = new HttpPut(endpoint + "/location/" + locationId);
        long timestamp = System.currentTimeMillis();

        method.addHeader("Content-Type", "application/json");
        method.addHeader("x-imaginary-version", CloudService.VERSION);
        method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp));
        method.addHeader("x-imaginary-api-key", apiKeyId);
        method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"),
                "put:/location/" + locationId + ":" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION));

        //noinspection deprecation
        method.setEntity(new StringEntity((new JSONObject(act)).toString(), "application/json", "UTF-8"));

        HttpResponse response;
        StatusLine status;

        try {
            response = client.execute(method);
            status = response.getStatusLine();
        } catch (IOException e) {
            e.printStackTrace();
            throw new CommunicationException(e);
        }
        if (status.getStatusCode() == HttpServletResponse.SC_OK) {
            String json = EntityUtils.toString(response.getEntity());
            JSONObject u = new JSONObject(json);

            System.out.println((u.has("pairingCode") && !u.isNull("pairingCode")) ? u.getString("pairingCode")
                    : "--no code--");
        } else {
            System.err.println("Failed to initialize pairing  (" + status.getStatusCode() + ": "
                    + EntityUtils.toString(response.getEntity()));
            System.exit(status.getStatusCode());
        }
    } else if (action.equalsIgnoreCase("create")) {
        if (args.length < 7) {
            System.err.println("create ENDPOINT NAME DESCRIPTION TIMEZONE API_KEY_ID API_KEY_SECRET");
            System.exit(-2);
            return;
        }
        String endpoint = args[1];
        String name = args[2];
        String description = args[3];
        String tz = args[4];
        String apiKeyId = args[5];
        String apiKeySecret = args[6];

        HashMap<String, Object> lstate = new HashMap<String, Object>();

        lstate.put("name", name);
        lstate.put("description", description);
        lstate.put("timeZone", tz);

        HttpParams params = new BasicHttpParams();

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        //noinspection deprecation
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUserAgent(params, "Imaginary Home");

        HttpClient client = new DefaultHttpClient(params);

        HttpPost method = new HttpPost(endpoint + "/location");
        long timestamp = System.currentTimeMillis();

        System.out.println(
                "Signing: " + "post:/location:" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION);
        method.addHeader("Content-Type", "application/json");
        method.addHeader("x-imaginary-version", CloudService.VERSION);
        method.addHeader("x-imaginary-timestamp", String.valueOf(timestamp));
        method.addHeader("x-imaginary-api-key", apiKeyId);
        method.addHeader("x-imaginary-signature", CloudService.sign(apiKeySecret.getBytes("utf-8"),
                "post:/location:" + apiKeyId + ":" + timestamp + ":" + CloudService.VERSION));

        //noinspection deprecation
        method.setEntity(new StringEntity((new JSONObject(lstate)).toString(), "application/json", "UTF-8"));

        HttpResponse response;
        StatusLine status;

        try {
            response = client.execute(method);
            status = response.getStatusLine();
        } catch (IOException e) {
            e.printStackTrace();
            throw new CommunicationException(e);
        }
        if (status.getStatusCode() == HttpServletResponse.SC_CREATED) {
            String json = EntityUtils.toString(response.getEntity());
            JSONObject u = new JSONObject(json);

            System.out.println((u.has("locationId") && !u.isNull("locationId")) ? u.getString("locationId")
                    : "--no location--");
        } else {
            System.err.println("Failed to create location  (" + status.getStatusCode() + ": "
                    + EntityUtils.toString(response.getEntity()));
            System.exit(status.getStatusCode());
        }
    } else {
        System.err.println("No such action: " + action);
        System.exit(-3);
    }
}

From source file:com.mellanox.r4h.TestWriteRead.java

/**
 * Entry point of the test when using a real cluster. 
 * Usage: [-loop ntimes] [-chunkSize nn] [-f filename] 
 *     [-useSeqRead |-usePosRead] [-append |-truncate] [-verbose |-noVerbose]
 * -loop: iterate ntimes: each iteration consists of a write, then a read 
 * -chunkSize: number of byte for each write
 * -f filename: filename to write and read 
 * [-useSeqRead | -usePosRead]: use Position Read, or default Sequential Read 
 * [-append | -truncate]: if file already exist, Truncate or default Append 
 * [-verbose | -noVerbose]: additional debugging messages if verbose is on
 * Default: -loop = 10; -chunkSize = 10000; -f filename = /tmp/fileX1
 *     Use Sequential Read, Append Mode, verbose on.
 *//*  w w w.ja  va 2 s .c  o  m*/
public static void main(String[] args) {
    try {
        TestWriteRead trw = new TestWriteRead();
        trw.initClusterModeTest();
        trw.getCmdLineOption(args);

        int stat = trw.clusterTestWriteRead1();

        if (stat == 0) {
            System.out.println("Status: clusterTestWriteRead1 test PASS");
        } else {
            System.out.println("Status: clusterTestWriteRead1 test FAIL with " + stat + " failures");
        }
        System.exit(stat);
    } catch (IOException e) {
        LOG.info("#### Exception in Main");
        e.printStackTrace();
        System.exit(-2);
    }
}

From source file:com.logicmonitor.ft.jxmtop.JMXTopMain.java

public static void main(String[] args) {

    RunParameter runParameter = ARGSAnalyser(args);
    if (!runParameter.isValid()) {
        System.out.println(runParameter.getValidInfo());
        System.out.println("<Please check your arguments>");
        exit(-1);/*from w  ww . jav a 2s.com*/
    }

    try {
        JMXMan jmxman = new JMXMan(runParameter.getSurl(), runParameter.getUsername(),
                runParameter.getPassword(), runParameter.getTimeout());
        jmxman.init(runParameter);
        topJMXValues(jmxman, runParameter);
    } catch (IOException e) {
        System.out.println("Fail to connect to process, check the surl,username and password");
        e.printStackTrace();
        exit(-1);
    }

}

From source file:examples.server2serverFTP.java

public static final void main(String[] args) {
    String server1, username1, password1, file1;
    String server2, username2, password2, file2;
    FTPClient ftp1, ftp2;//from w ww. ja  va  2 s.c om
    ProtocolCommandListener listener;

    if (args.length < 8) {
        System.err.println("Usage: ftp <host1> <user1> <pass1> <file1> <host2> <user2> <pass2> <file2>");
        System.exit(1);
    }

    server1 = args[0];
    username1 = args[1];
    password1 = args[2];
    file1 = args[3];
    server2 = args[4];
    username2 = args[5];
    password2 = args[6];
    file2 = args[7];

    listener = new PrintCommandListener(new PrintWriter(System.out));
    ftp1 = new FTPClient();
    ftp1.addProtocolCommandListener(listener);
    ftp2 = new FTPClient();
    ftp2.addProtocolCommandListener(listener);

    try {
        int reply;
        ftp1.connect(server1);
        System.out.println("Connected to " + server1 + ".");

        reply = ftp1.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp1.disconnect();
            System.err.println("FTP server1 refused connection.");
            System.exit(1);
        }
    } catch (IOException e) {
        if (ftp1.isConnected()) {
            try {
                ftp1.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
        System.err.println("Could not connect to server1.");
        e.printStackTrace();
        System.exit(1);
    }

    try {
        int reply;
        ftp2.connect(server2);
        System.out.println("Connected to " + server2 + ".");

        reply = ftp2.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp2.disconnect();
            System.err.println("FTP server2 refused connection.");
            System.exit(1);
        }
    } catch (IOException e) {
        if (ftp2.isConnected()) {
            try {
                ftp2.disconnect();
            } catch (IOException f) {
                // do nothing
            }
        }
        System.err.println("Could not connect to server2.");
        e.printStackTrace();
        System.exit(1);
    }

    __main: try {
        if (!ftp1.login(username1, password1)) {
            System.err.println("Could not login to " + server1);
            break __main;
        }

        if (!ftp2.login(username2, password2)) {
            System.err.println("Could not login to " + server2);
            break __main;
        }

        // Let's just assume success for now.
        ftp2.enterRemotePassiveMode();

        ftp1.enterRemoteActiveMode(InetAddress.getByName(ftp2.getPassiveHost()), ftp2.getPassivePort());

        // Although you would think the store command should be sent to server2
        // first, in reality, ftp servers like wu-ftpd start accepting data
        // connections right after entering passive mode.  Additionally, they
        // don't even send the positive preliminary reply until after the
        // transfer is completed (in the case of passive mode transfers).
        // Therefore, calling store first would hang waiting for a preliminary
        // reply.
        if (ftp1.remoteRetrieve(file1) && ftp2.remoteStoreUnique(file2)) {
            //      if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
            // We have to fetch the positive completion reply.
            ftp1.completePendingCommand();
            ftp2.completePendingCommand();
        } else {
            System.err.println("Couldn't initiate transfer.  Check that filenames are valid.");
            break __main;
        }

    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            if (ftp1.isConnected()) {
                ftp1.logout();
                ftp1.disconnect();
            }
        } catch (IOException e) {
            // do nothing
        }

        try {
            if (ftp2.isConnected()) {
                ftp2.logout();
                ftp2.disconnect();
            }
        } catch (IOException e) {
            // do nothing
        }
    }
}

From source file:gov.tva.sparky.util.indexer.IndexingAgent.java

public static void main(String[] args) {

    PropertyConfigurator.configure("conf/log4j.props");

    if (args.length < 2) {

        PrintUsage();//from  w  w w.j av a 2  s .c  o m

    } else {

        int i = 0;
        String cmd = args[i++];

        if ("-indexFile".equals(cmd)) {

            String strHdfsPath = args[i];

            System.out.println("Indexer > Scanning File: \n\n" + args[i] + "\n\n");

            try {

                LOG.info("Indexer > Indexing HDFS Physical File");
                Index_HDFS_File(strHdfsPath);

            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

        } else if ("-debugBucket".equals(cmd)) {

            String bucket_key = args[i++];

            DebugBucket(bucket_key);

        } else if ("-query".equals(cmd)) {

            //   String bucket_key = args[i++];
            System.out.println("Not Implemented Yet!");

        } else if ("-debugLookupTable".equals(cmd)) {

            String strHdfsPath = args[i];

            // does it exist in the archive?
            System.out.println("Not Implemented Yet!");

        } else if ("-deleteArchiveLookupPointers".equals(cmd)) {

            // you should never use this manually!!!

            String strHdfsPath = args[i++];
            DeleteArchiveLookupPointers(strHdfsPath);

        } else if ("-checkForArchive".equals(cmd)) {

            String strHdfsPath = args[i++];
            CheckForIndexedArchive(strHdfsPath);

        } else if ("-debugConfig".equals(cmd)) {

            DebugSparkyConfig();

        } else {

            PrintUsage();

        }

    }

}