001: /**
002: *
003: * Copyright (C) 2000-2003 Enterprise Distributed Technologies Ltd
004: *
005: * www.enterprisedt.com
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Bug fixes, suggestions and comments should be should posted on
022: * http://www.enterprisedt.com/forums/index.php
023: *
024: * Change Log:
025: *
026: * $Log: FTPPassiveDataSocket.java,v $
027: * Revision 1.7 2006/10/17 10:27:44 bruceb
028: * added closeChild()
029: *
030: * Revision 1.6 2006/10/11 08:58:29 hans
031: * made cvsId final
032: *
033: * Revision 1.5 2005/06/03 11:26:25 bruceb
034: * comment change
035: *
036: * Revision 1.4 2004/07/23 08:32:16 bruceb
037: * made cvsId public
038: *
039: * Revision 1.3 2003/11/15 11:23:55 bruceb
040: * changes required for ssl subclasses
041: *
042: * Revision 1.1 2003/11/02 21:49:52 bruceb
043: * implement FTPDataSocket interface
044: *
045: *
046: */package com.enterprisedt.net.ftp;
047:
048: import java.io.IOException;
049: import java.io.InputStream;
050: import java.io.OutputStream;
051: import java.net.Socket;
052:
053: /**
054: * Passive data socket handling class
055: *
056: * @author Bruce Blackshaw
057: * @version $Revision: 1.7 $
058: */
059: public class FTPPassiveDataSocket implements FTPDataSocket {
060:
061: /**
062: * Revision control id
063: */
064: public static final String cvsId = "@(#)$Id: FTPPassiveDataSocket.java,v 1.7 2006/10/17 10:27:44 bruceb Exp $";
065:
066: /**
067: * The underlying socket
068: */
069: protected Socket sock = null;
070:
071: /**
072: * Constructor
073: *
074: * @param sock client socket to use
075: */
076: protected FTPPassiveDataSocket(Socket sock) {
077: this .sock = sock;
078: }
079:
080: /**
081: * Set the TCP timeout on the underlying control socket.
082: *
083: * If a timeout is set, then any operation which
084: * takes longer than the timeout value will be
085: * killed with a java.io.InterruptedException.
086: *
087: * @param millis The length of the timeout, in milliseconds
088: */
089: public void setTimeout(int millis) throws IOException {
090: sock.setSoTimeout(millis);
091: }
092:
093: /**
094: * Returns the local port to which this socket is bound.
095: *
096: * @return the local port number to which this socket is bound
097: */
098: public int getLocalPort() {
099: return sock.getLocalPort();
100: }
101:
102: /**
103: * If active mode, accepts the FTP server's connection - in PASV,
104: * we are already connected. Then gets the output stream of
105: * the connection
106: *
107: * @return output stream for underlying socket.
108: */
109: public OutputStream getOutputStream() throws IOException {
110: return sock.getOutputStream();
111: }
112:
113: /**
114: * If active mode, accepts the FTP server's connection - in PASV,
115: * we are already connected. Then gets the input stream of
116: * the connection
117: *
118: * @return input stream for underlying socket.
119: */
120: public InputStream getInputStream() throws IOException {
121: return sock.getInputStream();
122: }
123:
124: /**
125: * Closes underlying socket
126: */
127: public void close() throws IOException {
128: sock.close();
129: }
130:
131: /**
132: * Does nothing in passive mode
133: */
134: public void closeChild() throws IOException {
135: // does nothing
136: }
137:
138: }
|