华南理工大学学报(自然科学版)
第29卷第8期 Journal of South China Universityof Technology Vol 29 N2o00812001年8月 (Natural Science Edition) August
Article ID: 1000- 565X(2001)08 - 0065 - 05A FTP Server Developed byJava
WanJiang-ping Huang Zhuo-ming Xia Zhi-zhong Zhang Peng
(College of Electronics&Information Eng , South China Univ of Tech , Guangzhou 510640, China)Abstract : In this paper , a FTP server prototyping system is developedbyJava based onthe analysis ofFile Transfer Protocol Implementation model and main class functions are explainedandthe imple2mentation for multi-threads and NVT(network virtual terminal) etc are discussed Finally, a solutionfor FTPproxy server is put forward
Key words : File Transfer Protocol ; Java; socket ; thread; network virtual terminal ; proxy server
CLC number : TP 31 1 52 Document code:A
0 Introduction WIN95/NT
The Java, developed bySun Microsystems , is 1 Concepts of FTP Model
FTP commands are generated bythe user-PI and destination host , the IP address andthe portpro2transmitted to the server process via the control videunique andaccurate exactlyidentificationforcconnection (The user mayestablisha direct con2 onnection between two machines The connec2titrol connection to the server-FTP and generate on is called socket A pair of sockets identifiesestandard FTP commands independently, while veryport connection: (1) sender socket=sourcebypassingthe user-FTPprocess) Standardreplies IP address +source port ; (2) receiver socket =are sent fromthe server-PI to the user-PI over the destination IPaddress+destinationportcontrol connectioninresponse to the commands Client sockets basedonconnectionareimple2
The FTP commands specify the parameters mented bysocket class andareusedtodevelop ap2for the data connection (data port , transfer plication which uses services provided by the ser-mode, representation type, and structure) and ver We can networkprogrambyjava netpacketthe nature of file system operation (store , re2 socket functions in APIs of Java Socket classtrieve, append, delete, etc ) User-DTP“ (Data” methods are listed in Table 1 , where getInput2Transter Prcess ) or its designate should listen Stream andohn thde specified daitaportd, adndthe serfveriinitiates2 for theyareusedtocommunicate to remotehostst e ata connect on an ata trans er n accor Table 1 Socket classmethods
notedthat the data port need not be in the same
receiving OutputStream Return OutputStream con2
The protocol requires the control connections getOutputStream() nectedthe socket
of the control connections when having finished ServerSocket class implements TCPserver’ susingthe FTP service,while it is the server who socket It provides two constructors which speci’2takes the action Theservermayabort data trans2 fies the server socket port to listen to a client sfer if the control connections are closed without connection request Its Accept () method enablescommand the server socket to listenandwaituntil the con2
The Relationship betweenFTPandTelnet is : nection is established When the connection isFTPuses Telnet protocol on the control connec2 done, it returns to a socket class instance whichtion This canbe achievedintwoways : first , the provides service for the clientuser-PI or the server-PI mayimplement the rules 2 2 FTPCommandsof the Telnetprotocol directlyintheir ownproce2 Common FTPcommands are:USER, PASS,dures; or , second, the user-PI or the server-PI CDUP, CDW, QUIT, PORT, TYPE, RETR,maymakeuse of the existing Telnet module inthe STOR, DELE,RMD,MKD,PWD,LIST,NLST,system NOOP etc We have implementedMINIMUM2 A FTP Server Devel2 1 JavaNetwork Programming fer to Reference [6] for the commands specifica2
When data arrive at the networklayer inthe tion
No 8 WanJiang-ping et al :AFTPServerDeveloped byJava 67
2 3 Development of the FTP Server The mainclass provides entryandthe server class2 3 1 FTPServer ImplementationModel listens to the connection and provides multi-users
FTP server addresses multi-users login at login, the ftpThreadis the core andprovides FTPsame time by thread There is a main thread in services, the NVT I/O classes deal with com2the FTPserver to listen to the client connection mands and messages between the clients and theWhenthe client connects to FTP server,A new serverthreadis createdfor it andcontrol is passedtothet There are two important methods in thehread which provides service for client It isn ftpThreadclass :ecessaryto convert NVT(NetworkVirtual Ter2 The run ( ) provides methods in which theminal) I/O to command or replying characters thread’ subclass must be overrided, initiateswhich is processed by program, the connectionc socket s input and output streams and executesontrol command and the reply should be com-p servicesproviding byftp()method, finallyclosesliantwiththe Telnetprotocol Finally, therearedi the connectedsocketsrectoryfunctions , file input and output , trans2 The ftp() interacts with clients, receivesmission parameters setting and user login etc commands and executes operations, and returnFigure 2is the FTPserver implementationmodel acknowledges
invokes run() method We demonstrate it using
Fig 2 FIP server implementation model the ftpThread class as follows :
According to themodel , the FTPserver con2sists of five classes : the mainclass providingpro2 c,
which is the core of FTP server to provide the NVTOutputStream out ;/ /output control streamFTP services , and the NVT I/O classes dealing NVTInputStreamin;//input control streamwith commands and replybetweenclients andthe static final int START=0;server //constant control start
There are five classes in the server program static final int FINISHED=1 ;
/ /constant control end public NVTInputStream(InputStream inStream,String hostName; / /Local host name OutputStream outStream)
Socket client ; //connection socket //ConstructorftpThread(Socket clnt ,String hn) { super(inStream) ; out=OutStream; }
/ /Accepts socket andlocal host name public int read() throws IOExceptionpublic void run() / / identify control codes
//invokes whenftpTreadinstance public String readLine() throws IOException / /{try Readinone line
{/ / Initialize control stream input and output }out=newNVTOutputStream(client getOut2 This class is designed for getting commandsputStream() ) ; from NVTInputStream It discards NVTcontrolin=new NVTInputStream(client getInput2 characters to getpure commands streamforserver
Stream() , out) ; in order to process commands which come fromftp() ;// Interprets FTP commands , re2 customerssponds to data connectionandtransfers data NVT OutputStream Class which correspondsclient close() ; to NVT InputStream is used to write NVT Out2
/ /Service is over, close user connection putStream into FTPclient acknowledge string
} //miss catch IOException for size limit 3 Conclusions
}
2 3 3 Network Virtual Terminal The FTPfunctionis still one of the most im2
Because the FTP controlling connection is portant Internet applications There are manybasedonthe Telnet protocol , theTelnetprotocol problems worth researching such as FTP proxysmust support NVTfor input and output device erver, security (e g combining with directorysThe FTP server should deal with NVT,which is ervice) and its applications (e g completelyim2an abstract device composed of printer and key2 plementing FTPcommands) It canhelp us toun2board Theuser input characters arepassedtothe derstandclient/server interaction in Internet andFTPserver, which returns the result to the user develop the FTP server using Java and be inte2by NVT printer output Carrier return combines gratedinto realworld applications The followingwith new line to terminate NTV control opera2 is a FTPproxyserver solution:tionswhichsupport interruptionanddiscardextra A FTPproxyserver connectionsessioncanbeoutterpret as Command) codewhich is a byte or two pandmore bytes following255 or0xff toindicate a
their implementation byJava :cknowledge and necessary data transferring areeclassNVTInputStreamextends FilterInputStream xecuted among the FTP client , the proxyservera{byte IAC = (byte) 0xff, DO = (byte) 0xfd, nd the FTP server; (5) the FTP client processclWILL=(byte)0xfb, CR=13,LF=10; oses the connection with FTP server; (6) theprint WONT = 252, DONT = 254, BUFFER- oxyserver closes the connectionwith the FTPserSIZE=1024, numBytes=0; ver
OutputStream out; It must be notedthat a FTPproxyis executedbyte lineBuffer =new byteBUFFER-SIZE; at awell-knownport andiswaitingfor client con2
No 8 WanJiang-ping et al :AFTPServerDeveloped byJava 69
nection, and FTPclient process is connectedwith owns independent thread
FTP proxy server correspondingly Therefore a
TCP connection is being built The control con2:nection keeps active during whole FTP process [ 1 ] Comer D E Computer Network and Internet MThe proxy protocol may include a series requests 2nd edition NewJersey:Prentice-Hall ,1999such as identity verifying, access controlling etc [2] Naik D C Internet Standard and Protocols M Wash 2If the connection request is allowed, the FTP ington:Microsoft Press ,1998proxyserver accepts the connection and requests
rewrites and filters the results , then sends the re2 [5] Postel J , Reynolds J Rfc959 File Transfer Protocolsults to the client process EB/OL htt p:/ /ds internic net/ rfc/ rfc959 txt ,1999-
There are three keypoints in system design: 1 1 - 07
(1) to sustain listening; (2) to build many bi-di2 [6] Thomas M D, Patel P,HudsonAD, et al Java Pro2rectional connections ; (3) every client process gramming for the Internet M North Carolina:
Ventana Communication Group Inc, 1997
用Java开发的FTP服务器
万江平 黄卓明 夏志忠 张 鹏
(华南理工大学电子与信息学院,广东广州510640)
摘 要:在分析FTP协议的基础上,用Java开发了一个FTP服务器原型系统,说明了其实现模型及各个类的功能,并讨论了多线程及虚拟网络终端等若干实现问题,最后给出了一种FTP代理服务器的解决方案关键词:文件传输协议; Java;套接字;线程;虚拟网络终端;代理服务器
中图分类号: TP31 1 52 文献标识码:A
文章编号: 1000- 565X(2001)08 - 0065 - 05
收稿日期: 1999- 12- 07
作者简介:万江平(1964) ,男,副教授,博士生,主要从事因特网应用信、息技术管理和复杂性科学的研究
totyun,新公司,主要运作香港vps、日本vps业务,接入cn2网络,不限制流量!VPS基于KVM虚拟,采用系统盘和数据盘分离,从4G内存开始支持Windows系统...大家注意下,网络分“Premium China”、“Global”,由于站长尚未测试,所以也还不清楚情况,有喜欢吃螃蟹的尝试过不妨告诉下站长。官方网站:https://totyun.com一次性5折优惠码:X4QTYVNB3P...
ZJI本月新上线了香港葵湾机房站群服务器,提供4个C段238个IPv4,支持使用8折优惠码,优惠后最低每月1400元起。ZJI是原Wordpress圈知名主机商家:维翔主机,成立于2011年,2018年9月更名为ZJI,提供中国香港、台湾、日本、美国独立服务器(自营/数据中心直营)租用及VDS、虚拟主机空间、域名注册等业务,所选数据中心均为国内普遍访问速度不错的机房。葵湾二型(4C站群)CPU:I...
官方网站:https://www.akkocloud.com/AkkoCloud新品英国伦敦CN2 GIA已上线三网回程CN2 GIA 国内速度优秀.电信去程CN2 GIALooking Glass:http://lonlg.akkocloud.com/Speedtest:http://lonlg.akkocloud.com/speedtest/新品上线刚好碰上国庆节 特此放上国庆专属九折循环优惠...