001 /* 002 * ftp4j - A pure Java FTP client library 003 * 004 * Copyright (C) 2008 Carlo Pelliccia (www.sauronsoftware.it) 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 package it.sauronsoftware.ftp4j.connectors; 020 021 import it.sauronsoftware.ftp4j.FTPConnection; 022 import it.sauronsoftware.ftp4j.FTPConnector; 023 024 import java.io.IOException; 025 import java.net.Socket; 026 027 import javax.net.SocketFactory; 028 import javax.net.ssl.SSLSocketFactory; 029 030 /** 031 * The SSLConnector connects the remote host using a SSL channel. 032 * 033 * @author Carlo Pelliccia 034 * @since 1.2 035 */ 036 public class SSLConnector implements FTPConnector { 037 038 /** 039 * The socket factory used by the connector. 040 */ 041 private SSLSocketFactory factory = null; 042 043 /** 044 * Returns the socket factory used by the connector. 045 * 046 * @return The socket factory. 047 * @since 1.3 048 */ 049 public SSLSocketFactory getSSLSocketFactory() { 050 return factory; 051 } 052 053 /** 054 * Sets the socket factory used by the connector. 055 * 056 * @param factory 057 * The socket factory. 058 * @since 1.3 059 */ 060 public void setSSLSocketFactory(SSLSocketFactory factory) { 061 this.factory = factory; 062 } 063 064 public FTPConnection connectForCommunicationChannel(String host, int port) 065 throws IOException { 066 // SSL connection. 067 SocketFactory myFactory = factory != null ? factory : SSLSocketFactory 068 .getDefault(); 069 Socket socket = myFactory.createSocket(host, port); 070 return new SocketConnection(socket); 071 } 072 073 public FTPConnection connectForDataTransferChannel(String host, int port) 074 throws IOException { 075 // Plain connection. 076 Socket socket = new Socket(host, port); 077 return new SocketConnection(socket); 078 } 079 080 }