apache ftpClient 多网卡上传文件超时解决。
来源:互联网 发布:苹果手机快手软件 编辑:程序博客网 时间:2024/05/13 12:23
在服务器中有多个网卡,默认的路由不是当前的ftp服务器走的路由。
修改ftpclinent.java 中的代码实现。
protected Socket _openDataConnection_(String command, String arg) throws IOException {if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE&& __dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE) {return null;}final boolean isInet6Address = getRemoteAddress() instanceof Inet6Address;Socket socket;if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE) {// if no activePortRange was set (correctly) -> getActivePort() = 0// -> new ServerSocket(0) -> bind to any free local portServerSocket server = _serverSocketFactory_.createServerSocket(getActivePort(), 1, getHostAddress());try {// Try EPRT only if remote server is over IPv6, if not use PORT,// because EPRT has no advantage over PORT on IPv4.// It could even have the disadvantage,// that EPRT will make the data connection fail, because// today's intelligent NAT Firewalls are able to// substitute IP addresses in the PORT command,// but might not be able to recognize the EPRT command.if (isInet6Address) {if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort()))) {return null;}} else {if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort()))) {return null;}}if ((__restartOffset > 0) && !restart(__restartOffset)) {return null;}if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {return null;}// For now, let's just use the data timeout value for waiting for// the data connection. It may be desirable to let this be a// separately configurable value. In any case, we really want// to allow preventing the accept from blocking indefinitely.if (__dataTimeout >= 0) {server.setSoTimeout(__dataTimeout);}socket = server.accept();} finally {server.close();}} else { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE// Try EPSV command first on IPv6 - and IPv4 if enabled.// When using IPv4 with NAT it has the advantage// to work with more rare configurations.// E.g. if FTP server has a static PASV address (external network)// and the client is coming from another internal network.// In that case the data connection after PASV command would fail,// while EPSV would make the client succeed by taking just the port.boolean attemptEPSV = isUseEPSVwithIPv4() || isInet6Address;if (attemptEPSV && epsv() == FTPReply.ENTERING_EPSV_MODE) {_parseExtendedPassiveModeReply(_replyLines.get(0));} else {if (isInet6Address) {return null; // Must use EPSV for IPV6}// If EPSV failed on IPV4, revert to PASVif (pasv() != FTPReply.ENTERING_PASSIVE_MODE) {return null;}_parsePassiveModeReply(_replyLines.get(0));}socket = _socketFactory_.createSocket();// 新增加bind 源地址操作。if (localAddr != null) {System.out.println(">>>>>>>>>>>>>>>>>>FTPClient localAddr"+localAddr); socket.bind(new InetSocketAddress(localAddr, localPort));}socket.connect(new InetSocketAddress(__passiveHost, __passivePort), connectTimeout);if ((__restartOffset > 0) && !restart(__restartOffset)) {socket.close();return null;}if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {socket.close();return null;}}if (__remoteVerificationEnabled && !verifyRemote(socket)) {socket.close();throw new IOException("Host attempting data connection " + socket.getInetAddress().getHostAddress()+ " is not same as server " + getRemoteAddress().getHostAddress());}if (__dataTimeout >= 0) {socket.setSoTimeout(__dataTimeout);}return socket;}
- apache ftpClient 多网卡上传文件超时解决。
- apache ftpClient 文件上传
- Apache FTPClient上传文件时的问题及解决
- Apache FTPClient 实现文件上传
- 解决FTPClient上传文件为空
- apache ftpClient 复制文件
- Apache FTPClient上传下载文件
- FTPCLIENT上传文件
- FTPClient上传文件乱码
- ftpclient上传文件
- 解决FTPClient上传文件时文件被破坏问题
- FTPClient上传、下载文件方法
- org.apache.commons.net.ftp.FTPClient----根据文件名,路径检索文件 FTP上传 下载 删除文件
- apache.commons.net.ftp.FTPClient上传FTP
- FTP文件的上传和下载---org.apache.commons.net.ftp.FTPClient
- FTP文件的上传和下载---org.apache.commons.net.ftp.FTPClient
- 使用Apache-FTPClient完成文件上传和从配置文件中读取properties的使用
- ftpClient解决中文乱码问题(apache)
- Maxima 的三角函数化简功能
- 随机数,自己老忘
- 注册表操作
- ios开发知识点汇总
- c# 读取rtf后,不保存关闭
- apache ftpClient 多网卡上传文件超时解决。
- poj Secret Milking Machine
- poj3608 Bridge Across Islands (旋转卡壳之两凸包最短距)
- hdu 1257 最少拦截系统 (暴力版&温柔版/强力注释版)
- poj2079 Triangle (旋转卡壳之最大三角形)
- 蓝牙开发的一些网站和博客文章地址
- 国甲魔方
- The way to fix error: Lexical or Preprocessor Issue 'libxml/xmlversion.h' file not found
- 关于加班