/*
 * @(#)FtpsImplicitTransfer.java
 *
 * Copyright (c) 1999-2007 JSCAPE LLC
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */
package com.jscape.filetransfer;

import com.jscape.inet.ftps.Ftps;

import java.io.File;
import java.util.Collections;
import java.util.Set;

/**
 * Implements the basic functionality of a FTPS client using implicit SSL.
 * <p/>
 * <p/>
 * <p/> Example Usage:
 * <p/>
 * <p/>
 * <p/>
 * <pre>
 *  // create new FtpsTransfer instance
 *  FileTransfer ftp = new FtpsImplicitTransfer(&quot;ftp.myserver.com&quot;,&quot;anonymous&quot;,&quot;user@myserver.com&quot;);
 *  ftp.setPort(990);
 *
 *  try {
 *  // connect to FTP server
 *  ftp.connect();
 *  &lt;p/&gt;
 *  // print out directory listing
 *  System.out.println(ftp.getDirListingAsString());
 *  &lt;p/&gt;
 *  // disconnect from FTP server
 *  ftp.disconnect();
 *  } catch(Exception e) {
 *  System.out.println(e);
 *  }
 * </pre>
 */
public class FtpsImplicitTransfer
        extends FtpsTransfer {

    public FtpsImplicitTransfer(String host, int port, String user, String password, File localDirectory, Set<FileTransferListener> listeners) {
        super(host, port, user, password, localDirectory, listeners);
        this.ftps.setConnectionType(Ftps.IMPLICIT_SSL);
    }

    /**
     * Creates FtpsImplicitTransfer instance.
     *
     * @param host           the hostname of FTP server
     * @param user           the username of FTP user
     * @param pwd            the password of FTP user
     * @param localDirectory the local directory to be used for transferring files
     */
    public FtpsImplicitTransfer(String host, String user, String pwd, File localDirectory) {
        this(host, 990, user, pwd, localDirectory, Collections.<FileTransferListener>emptySet());
    }

    /**
     * Creates FtpsImplicitTransfer instance.
     *
     * @param host the hostname of FTP server
     * @param user the username of FTP user
     * @param pwd  the password of FTP user
     * @param port the port of FTP server
     */
    public FtpsImplicitTransfer(String host, String user, String pwd, int port) {
        this(host, port, user, pwd, new File("."), Collections.<FileTransferListener>emptySet());
    }

    /**
     * Creates FtpsImplicitTransfer instance.
     *
     * @param host the hostname of FTP server
     * @param user the username of FTP user
     * @param pwd  the password of FTP user
     */
    public FtpsImplicitTransfer(String host, String user, String pwd) {
        this(host, user, pwd, 990);
    }

    /**
     * Creates FtpsImplicitTransfer instance.
     *
     * @param host the hostname
     * @param user the username
     * @param pwd  the password
     * @param port the port
     */
    public FtpsImplicitTransfer(String host, String user, String pwd, Integer port) {
        this(host, user, pwd, port.intValue());
    }


    /**
     * Creates FtpsImplicitTransfer instance.
     */
    public FtpsImplicitTransfer() {
        this("", "", "");
    }

    public FileTransfer copy() {
        FtpsImplicitTransfer transfer = new FtpsImplicitTransfer(this.ftps.getHostname(),
                                                                 this.ftps.getPort(),
                                                                 this.ftps.getUsername(),
                                                                 this.ftps.getPassword(),
                                                                 this.ftps.getLocalDir(),
                                                                 this.listeners);
        transfer.setDebugStream(getDebugStream());
        transfer.setDebug(getDebug());

        return transfer;
    }
}
