ftpiosession.java
来自「JAVA FTP 上传下载 的源文件」· Java 代码 · 共 852 行 · 第 1/2 页
JAVA
852 行
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.ftpserver.impl;import java.net.InetSocketAddress;import java.net.SocketAddress;import java.security.cert.Certificate;import java.util.Date;import java.util.Set;import java.util.UUID;import javax.net.ssl.SSLPeerUnverifiedException;import javax.net.ssl.SSLSession;import org.apache.ftpserver.ftplet.DataType;import org.apache.ftpserver.ftplet.FileSystemView;import org.apache.ftpserver.ftplet.FtpFile;import org.apache.ftpserver.ftplet.FtpReply;import org.apache.ftpserver.ftplet.FtpSession;import org.apache.ftpserver.ftplet.Structure;import org.apache.ftpserver.ftplet.User;import org.apache.ftpserver.listener.Listener;import org.apache.mina.core.filterchain.IoFilterChain;import org.apache.mina.core.future.CloseFuture;import org.apache.mina.core.future.ReadFuture;import org.apache.mina.core.future.WriteFuture;import org.apache.mina.core.service.IoHandler;import org.apache.mina.core.service.IoService;import org.apache.mina.core.service.TransportMetadata;import org.apache.mina.core.session.AbstractIoSession;import org.apache.mina.core.session.IdleStatus;import org.apache.mina.core.session.IoSession;import org.apache.mina.core.session.IoSessionConfig;import org.apache.mina.core.write.WriteRequest;import org.apache.mina.core.write.WriteRequestQueue;import org.apache.mina.filter.ssl.SslFilter;/** * <strong>Internal class, do not use directly.</strong> * * @author The Apache MINA Project (dev@mina.apache.org) * @version $Rev$, $Date$ * */public class FtpIoSession implements IoSession { /** * Contains user name between USER and PASS commands */ public static final String ATTRIBUTE_PREFIX = "org.apache.ftpserver."; private static final String ATTRIBUTE_USER_ARGUMENT = ATTRIBUTE_PREFIX + "user-argument"; private static final String ATTRIBUTE_SESSION_ID = ATTRIBUTE_PREFIX + "session-id"; private static final String ATTRIBUTE_USER = ATTRIBUTE_PREFIX + "user"; private static final String ATTRIBUTE_LANGUAGE = ATTRIBUTE_PREFIX + "language"; private static final String ATTRIBUTE_LOGIN_TIME = ATTRIBUTE_PREFIX + "login-time"; private static final String ATTRIBUTE_DATA_CONNECTION = ATTRIBUTE_PREFIX + "data-connection"; private static final String ATTRIBUTE_FILE_SYSTEM = ATTRIBUTE_PREFIX + "file-system"; private static final String ATTRIBUTE_RENAME_FROM = ATTRIBUTE_PREFIX + "rename-from"; private static final String ATTRIBUTE_FILE_OFFSET = ATTRIBUTE_PREFIX + "file-offset"; private static final String ATTRIBUTE_DATA_TYPE = ATTRIBUTE_PREFIX + "data-type"; private static final String ATTRIBUTE_STRUCTURE = ATTRIBUTE_PREFIX + "structure"; private static final String ATTRIBUTE_FAILED_LOGINS = ATTRIBUTE_PREFIX + "failed-logins"; private static final String ATTRIBUTE_LISTENER = ATTRIBUTE_PREFIX + "listener"; private static final String ATTRIBUTE_MAX_IDLE_TIME = ATTRIBUTE_PREFIX + "max-idle-time"; private static final String ATTRIBUTE_LAST_ACCESS_TIME = ATTRIBUTE_PREFIX + "last-access-time"; private static final String ATTRIBUTE_CACHED_REMOTE_ADDRESS = ATTRIBUTE_PREFIX + "cached-remote-address"; private IoSession wrappedSession; private FtpServerContext context; /** * Last reply that was sent to the client, if any. */ private FtpReply lastReply = null; /* Begin wrapped IoSession methods */ /** * @see IoSession#close() */ public CloseFuture close() { return wrappedSession.close(); } /** * @see IoSession#close(boolean) */ public CloseFuture close(boolean immediately) { return wrappedSession.close(immediately); } /** * @see IoSession#containsAttribute(Object) */ public boolean containsAttribute(Object key) { return wrappedSession.containsAttribute(key); } /** * @see IoSession#getAttachment() */ @SuppressWarnings("deprecation") public Object getAttachment() { return wrappedSession.getAttachment(); } /** * @see IoSession#getAttribute(Object) */ public Object getAttribute(Object key) { return wrappedSession.getAttribute(key); } /** * @see IoSession#getAttribute(Object, Object) */ public Object getAttribute(Object key, Object defaultValue) { return wrappedSession.getAttribute(key, defaultValue); } /** * @see IoSession#getAttributeKeys() */ public Set<Object> getAttributeKeys() { return wrappedSession.getAttributeKeys(); } /** * @see IoSession#getBothIdleCount() */ public int getBothIdleCount() { return wrappedSession.getBothIdleCount(); } /** * @see IoSession#getCloseFuture() */ public CloseFuture getCloseFuture() { return wrappedSession.getCloseFuture(); } /** * @see IoSession#getConfig() */ public IoSessionConfig getConfig() { return wrappedSession.getConfig(); } /** * @see IoSession#getCreationTime() */ public long getCreationTime() { return wrappedSession.getCreationTime(); } /** * @see IoSession#getFilterChain() */ public IoFilterChain getFilterChain() { return wrappedSession.getFilterChain(); } /** * @see IoSession#getHandler() */ public IoHandler getHandler() { return wrappedSession.getHandler(); } /** * @see IoSession#getId() */ public long getId() { return wrappedSession.getId(); } /** * @see IoSession#getIdleCount(IdleStatus) */ public int getIdleCount(IdleStatus status) { return wrappedSession.getIdleCount(status); } /** * @see IoSession#getLastBothIdleTime() */ public long getLastBothIdleTime() { return wrappedSession.getLastBothIdleTime(); } /** * @see IoSession#getLastIdleTime(IdleStatus) */ public long getLastIdleTime(IdleStatus status) { return wrappedSession.getLastIdleTime(status); } /** * @see IoSession#getLastIoTime() */ public long getLastIoTime() { return wrappedSession.getLastIoTime(); } /** * @see IoSession#getLastReadTime() */ public long getLastReadTime() { return wrappedSession.getLastReadTime(); } /** * @see IoSession#getLastReaderIdleTime() */ public long getLastReaderIdleTime() { return wrappedSession.getLastReaderIdleTime(); } /** * @see IoSession#getLastWriteTime() */ public long getLastWriteTime() { return wrappedSession.getLastWriteTime(); } /** * @see IoSession#getLastWriterIdleTime() */ public long getLastWriterIdleTime() { return wrappedSession.getLastWriterIdleTime(); } /** * @see IoSession#getLocalAddress() */ public SocketAddress getLocalAddress() { return wrappedSession.getLocalAddress(); } /** * @see IoSession#getReadBytes() */ public long getReadBytes() { return wrappedSession.getReadBytes(); } /** * @see IoSession#getReadBytesThroughput() */ public double getReadBytesThroughput() { return wrappedSession.getReadBytesThroughput(); } /** * @see IoSession#getReadMessages() */ public long getReadMessages() { return wrappedSession.getReadMessages(); } /** * @see IoSession#getReadMessagesThroughput() */ public double getReadMessagesThroughput() { return wrappedSession.getReadMessagesThroughput(); } /** * @see IoSession#getReaderIdleCount() */ public int getReaderIdleCount() { return wrappedSession.getReaderIdleCount(); } /** * @see IoSession#getRemoteAddress() */ public SocketAddress getRemoteAddress() { // when closing a socket, the remote address might be reset to null // therefore, we attempt to keep a cached copy around SocketAddress address = wrappedSession.getRemoteAddress(); if (address == null && containsAttribute(ATTRIBUTE_CACHED_REMOTE_ADDRESS)) { return (SocketAddress) getAttribute(ATTRIBUTE_CACHED_REMOTE_ADDRESS); } else { setAttribute(ATTRIBUTE_CACHED_REMOTE_ADDRESS, address); return address; } } /** * @see IoSession#getScheduledWriteBytes() */ public long getScheduledWriteBytes() { return wrappedSession.getScheduledWriteBytes(); } /** * @see IoSession#getScheduledWriteMessages() */ public int getScheduledWriteMessages() { return wrappedSession.getScheduledWriteMessages(); } /** * @see IoSession#getService() */ public IoService getService() { return wrappedSession.getService(); } /** * @see IoSession#getServiceAddress() */ public SocketAddress getServiceAddress() { return wrappedSession.getServiceAddress(); } /** * @see IoSession#getTransportMetadata() */ public TransportMetadata getTransportMetadata() { return wrappedSession.getTransportMetadata(); } /** * @see IoSession#getWriterIdleCount() */ public int getWriterIdleCount() { return wrappedSession.getWriterIdleCount(); } /** * @see IoSession#getWrittenBytes() */ public long getWrittenBytes() { return wrappedSession.getWrittenBytes(); } /** * @see IoSession#getWrittenBytesThroughput() */ public double getWrittenBytesThroughput() { return wrappedSession.getWrittenBytesThroughput(); } /** * @see IoSession#getWrittenMessages() */ public long getWrittenMessages() { return wrappedSession.getWrittenMessages(); } /** * @see IoSession#getWrittenMessagesThroughput() */ public double getWrittenMessagesThroughput() { return wrappedSession.getWrittenMessagesThroughput(); } /** * @see IoSession#isClosing() */ public boolean isClosing() { return wrappedSession.isClosing(); } /** * @see IoSession#isConnected() */ public boolean isConnected() { return wrappedSession.isConnected(); } /** * @see IoSession#isIdle(IdleStatus)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?