package org.g4studio.core.net.ftp;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import org.g4studio.core.net.MalformedServerReplyException;
import org.g4studio.core.net.ftp.parser.DefaultFTPFileEntryParserFactory;
import org.g4studio.core.net.ftp.parser.FTPFileEntryParserFactory;
import org.g4studio.core.net.ftp.parser.ParserInitializationException;
import org.g4studio.core.net.io.CopyStreamEvent;
import org.g4studio.core.net.io.CopyStreamException;
import org.g4studio.core.net.io.FromNetASCIIInputStream;
import org.g4studio.core.net.io.SocketInputStream;
import org.g4studio.core.net.io.SocketOutputStream;
import org.g4studio.core.net.io.ToNetASCIIOutputStream;
import org.g4studio.core.net.io.Util;
/***
* FTPClient encapsulates all the functionality necessary to store and retrieve
* files from an FTP server. This class takes care of all low level details of
* interacting with an FTP server and provides a convenient higher level
* interface. As with all classes derived from
* {@link org.apache.commons.net.SocketClient}, you must first connect to the
* server with {@link org.apache.commons.net.SocketClient#connect connect }
* before doing anything, and finally
* {@link org.apache.commons.net.SocketClient#disconnect disconnect } after
* you're completely finished interacting with the server. Then you need to
* check the FTP reply code to see if the connection was successful. For
* example:
*
* <pre>
* boolean error = false;
* try {
* int reply;
* ftp.connect("ftp.foobar.com");
* System.out.println("Connected to " + server + ".");
* System.out.print(ftp.getReplyString());
*
* // After connection attempt, you should check the reply code to verify
* // success.
* reply = ftp.getReplyCode();
*
* if(!FTPReply.isPositiveCompletion(reply)) {
* ftp.disconnect();
* System.err.println("FTP server refused connection.");
* System.exit(1);
* }
* ... // transfer files
* ftp.logout();
* } catch(IOException e) {
* error = true;
* e.printStackTrace();
* } finally {
* if(ftp.isConnected()) {
* try {
* ftp.disconnect();
* } catch(IOException ioe) {
* // do nothing
* }
* }
* System.exit(error ? 1 : 0);
* }
* </pre>
* <p>
* Immediately after connecting is the only real time you need to check the
* reply code (because connect is of type void). The convention for all the FTP
* command methods in FTPClient is such that they either return a boolean value
* or some other value. The boolean methods return true on a successful
* completion reply from the FTP server and false on a reply resulting in an
* error condition or failure. The methods returning a value other than boolean
* return a value containing the higher level data produced by the FTP command,
* or null if a reply resulted in an error condition or failure. If you want to
* access the exact FTP reply code causing a success or failure, you must call
* {@link org.apache.commons.net.ftp.FTP#getReplyCode getReplyCode } after a
* success or failure.
* <p>
* The default settings for FTPClient are for it to use
* <code> FTP.ASCII_FILE_TYPE </code>, <code> FTP.NON_PRINT_TEXT_FORMAT </code>,
* <code> FTP.STREAM_TRANSFER_MODE </code>, and
* <code> FTP.FILE_STRUCTURE </code>. The only file types directly supported are
* <code> FTP.ASCII_FILE_TYPE </code> and <code> FTP.IMAGE_FILE_TYPE </code>
* (which is the same as <code> FTP.BINARY_FILE_TYPE </code>). Because there are
* at lest 4 different EBCDIC encodings, we have opted not to provide direct
* support for EBCDIC. To transfer EBCDIC and other unsupported file types you
* must create your own filter InputStreams and OutputStreams and wrap them
* around the streams returned or required by the FTPClient methods. FTPClient
* uses the {@link ToNetASCIIOutputStream NetASCII} filter streams to provide
* transparent handling of ASCII files. We will consider incorporating EBCDIC
* support if there is enough demand.
* <p>
* <code> FTP.NON_PRINT_TEXT_FORMAT </code>,
* <code> FTP.STREAM_TRANSFER_MODE </code>, and
* <code> FTP.FILE_STRUCTURE </code> are the only supported formats, transfer
* modes, and file structures.
* <p>
* Because the handling of sockets on different platforms can differ
* significantly, the FTPClient automatically issues a new PORT command prior to
* every transfer requiring that the server connect to the client's data port.
* This ensures identical problem-free behavior on Windows, Unix, and Macintosh
* platforms. Additionally, it relieves programmers from having to issue the
* PORT command themselves and dealing with platform dependent issues.
* <p>
* Additionally, for security purposes, all data connections to the client are
* verified to ensure that they originated from the intended party (host and
* port). If a data connection is initiated by an unexpected party, the command
* will close the socket and throw an IOException. You may disable this behavior
* with {@link #setRemoteVerificationEnabled setRemoteVerificationEnabled()}.
* <p>
* You should keep in mind that the FTP server may choose to prematurely close a
* connection if the client has been idle for longer than a given time period
* (usually 900 seconds). The FTPClient class will detect a premature FTP server
* connection closing when it receives a
* {@link org.apache.commons.net.ftp.FTPReply#SERVICE_NOT_AVAILABLE
* FTPReply.SERVICE_NOT_AVAILABLE } response to a command. When that occurs, the
* FTP class method encountering that reply will throw an
* {@link org.apache.commons.net.ftp.FTPConnectionClosedException} .
* <code>FTPConnectionClosedException</code> is a subclass of
* <code> IOException </code> and therefore need not be caught separately, but
* if you are going to catch it separately, its catch block must appear before
* the more general <code> IOException </code> catch block. When you encounter
* an {@link org.apache.commons.net.ftp.FTPConnectionClosedException} , you must
* disconnect the connection with {@link #disconnect disconnect() } to properly
* clean up the system resources used by FTPClient. Before disconnecting, you
* may check the last reply code and text with
* {@link org.apache.commons.net.ftp.FTP#getReplyCode getReplyCode },
* {@link org.apache.commons.net.ftp.FTP#getReplyString getReplyString }, and
* {@link org.apache.commons.net.ftp.FTP#getReplyStrings getReplyStrings}. You
* may avoid server disconnections while the client is idle by periodicaly
* sending NOOP commands to the server.
* <p>
* Rather than list it separately for each method, we mention here that every
* method communicating with the server and throwing an IOException can also
* throw a {@link org.apache.commons.net.MalformedServerReplyException} , which
* is a subclass of IOException. A MalformedServerReplyException will be thrown
* when the reply received from the server deviates enough from the protocol
* specification that it cannot be interpreted in a useful manner despite
* attempts to be as lenient as possible.
* <p>
* Listing API Examples Both paged and unpaged examples of directory listings
* are available, as follows:
* <p>
* Unpaged (whole list) access, using a parser accessible by auto-detect:
*
* <pre>
* FTPClient f = FTPClient();
* f.connect(server);
* f.login(username, password);
* FTPFile[] files = listFiles(directory);
* </pre>
* <p>
* Paged access, using a parser not accessible by auto-detect. The class defined
* in the first parameter of initateListParsing should be derived from
* org.apache.commons.net.FTPFileEntryParser:
没有合适的资源?快使用搜索试试~ 我知道了~
G4Studio行业应用二次快速开发平台基于JavaEE技术体系,面向中小软件企业.zip
共2000个文件
java:758个
gif:382个
js:181个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 117 浏览量
2024-02-09
13:06:36
上传
评论
收藏 95.74MB ZIP 举报
温馨提示
快应用开发
资源推荐
资源详情
资源评论
收起资源包目录
G4Studio行业应用二次快速开发平台基于JavaEE技术体系,面向中小软件企业.zip (2000个子文件)
G4Studio版本变更日志.chm 39KB
ext-all.css 136KB
ext-all.css 131KB
ext-all.css 131KB
ext-all.css 131KB
ext-all.css 131KB
ext-all.css 131KB
ext-all.css 131KB
ext-all.css 131KB
ext-all-notheme.css 94KB
ux-all.css 17KB
uploadPanel.css 15KB
desktop.css 13KB
grid.css 10KB
form.css 10KB
button.css 8KB
panel.css 7KB
tabs.css 7KB
ext_icon.css 7KB
panel-reset.css 6KB
grid.css 6KB
GroupTab.css 6KB
toolbar.css 5KB
core.css 5KB
layout.css 5KB
date-picker.css 5KB
tree.css 4KB
htmleditorplugins.css 4KB
menu.css 4KB
window.css 3KB
tree.css 3KB
tabs.css 3KB
editor.css 3KB
resizable.css 3KB
date-picker.css 3KB
statusbar.css 3KB
toolbar.css 3KB
qtips.css 3KB
form.css 2KB
button.css 2KB
panel.css 2KB
slider.css 2KB
window.css 2KB
menu.css 2KB
ext_css_patch.css 2KB
resizable.css 2KB
core.css 2KB
list-view.css 1KB
RowEditor.css 1KB
box.css 1KB
box.css 1KB
Spinner.css 1KB
ColumnNodeUI.css 1KB
Spinner.css 1KB
layout.css 1KB
g4studio.css 1KB
qtips.css 1KB
dialog.css 1KB
GridFilters.css 1KB
treegrid.css 1KB
borders.css 1KB
dd.css 1004B
debug.css 915B
combo.css 887B
Ext.ux.grid.GridSummary.css 871B
dialog.css 809B
combo.css 785B
list-view.css 774B
progress.css 757B
MultiSelect.css 688B
Portal.css 688B
dd.css 636B
slider.css 633B
progress.css 623B
fileuploadfield.css 581B
debug.css 552B
GroupSummary.css 546B
borders.css 530B
LockingGridView.css 529B
debug.css 488B
reset.css 463B
reset-min.css 463B
PanelResizer.css 458B
RangeMenu.css 399B
htmleditor.css 378B
editor.css 301B
CenterLayout.css 289B
ColumnHeaderGroup.css 246B
Thumbs.db 183KB
Thumbs.db 73KB
Thumbs.db 46KB
Thumbs.db 42KB
Thumbs.db 39KB
Thumbs.db 36KB
Thumbs.db 33KB
Thumbs.db 27KB
Thumbs.db 25KB
Thumbs.db 19KB
Thumbs.db 18KB
Thumbs.db 18KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
博士僧小星
- 粉丝: 1711
- 资源: 5876
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功