

下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、java做的比较完善的ftp上传下载文件服务器源码 java做的比较完善的ftp上传下载文件服务器源码 filename: ftp.java author: leetsing(elove) create date: 2021-08-30 use: connect to ftp server,then upload and download file modify date: 2021-09-05 add to upload file 2021-09-13 add to download file copy right: magisky media technology co.,ltd. * 字
2、串7 */ /import cz.dhl.io.*; /import cz.dhl.ftp.*; import .ftp.*; import .*; import java.applet.*; import java.io.*; import java.io.ioexception; import java.util.stringtokenizer; import .ftp.ftpclient; import java.util.arraylist; public class ftp extends applet ftpclient aftp; dataoutputstream outputs
3、 ; telnetinputstream ins; telnetoutputstream outs; int ch; public string a; string hostname=; private string path = /; public static void main(string args) string hostname = 6; int port = 2121; string uid = lee; string pwd = lee; string rwfiledir = d:smsftp;/文件名目 java做的比较完善的ftp上传下载文件服务器源码
4、 /连接ftp服务器 ftp ft = new ftp(); ft.connect(rwfiledir,hostname,port,uid,pwd); 字串3 /下载文件 if (ft.aftp != null) try ft.getnamelist(rwfiledir); catch(ioexception e) system.out.println(下载文件出错:+e); /上传文件 if (ft.aftp != null) string sdir = rwfiledir + subunsubfromsp; file fdir = new file(sdir); string filena
5、me = ; for(int i=0;i filename = sdir + (fdir.list()i; ft.uploadfile(rwfiledir,filename); /system.out.println(胜利上传的文件:); /ft.showfilecontents(subunsubfromsp); /删除subunsubfromsp名目下已经上传的文件文件 字串6 / ft.delefile(rwfiledir); /断开服务器连接 ft.stop(rwfiledir); public ftpclient connect(string rwfiledir,string host
6、name,int uid,string pwd) this.hostname = hostname; port,string java做的比较完善的ftp上传下载文件服务器源码 system.out.println(正在连接+hostname+,请等待.); try aftp = new ftpclient(hostname,port); aftp.login(uid,pwd); aftp.binary(); /aftp.openportdataconnection(); a = 连接主机:+hostname+胜利!; system.out.println(a); catch(ftplogin
7、exception e) a=登陆主机:+hostname+失败!请检查用户名或密码是否正确:+e; system.out.println(a); /return false; catch (ioexception e) a=连接主机:+hostname+失败!请检查端口是否正确:+e; 字串3 system.out.println(a); /return false; catch(securityexception e) a=无权限与主机:+hostname+连接!请检查是否有访问权限:+e; system.out.println(a); /return false; log(rwfiled
8、ir,a); return aftp; public void stop(string rwfiledir) string message = ; try if(aftp!=null) aftp.closeserver(); message = 与主机+hostname+连接已断开!; system.out.println(message); log(rwfiledir,message); catch(ioexception e) message = 与主机+hostname+断开连接失败!+e; 字串2 java做的比较完善的ftp上传下载文件服务器源码 system.out.println
9、(message); log(rwfiledir,message); public boolean downloadfile(string rwfiledir,string filepathname) boolean result=true; string message = ; if (aftp != null) system.out.println(正在下载文件+filepathname+,请等待.); string badfile filepathname.substring(filepathname.length()-4,filepathname.length(); string ba
10、dlog filepathname.substring(filepathname.length()-7,filepathname.length(); = = string baddir = ; if (pareto(.bad) != 0) (pareto(.badlog) != 0) baddir = subunsubtosp; else baddir = bad; 字串9 string strdir = subunsubtosp; /system.out.println(rwfiledir + baddir + filepathname); try /ftpclient fc=new ftp
11、client(6,2121); /fc.login(lee,lee); int ch; file fi = new file(rwfiledir + baddir + filepathname); /aftp.cd(strdir); randomaccessfile getfile = new randomaccessfile(fi,rw); getfile.seek(0); telnetinputstream fget=aftp.get(strdir+filepathname); datainputstream puts = new datainputstream(fg
12、et); while (ch = puts.read() = 0) getfile.write(ch); /s.delete(); 字串1 fget.close(); getfile.close(); /fc.closeserver(); java做的比较完善的ftp上传下载文件服务器源码 message = 下载+filepathname+文件到+baddir +名目胜利!; system.out.println(message); log(rwfiledir,message); catch(ioexception e) message = 下载+filepathname+文件到+baddi
13、r +名目失败!+e; system.out.println(message); log(rwfiledir,message); result = false ; else result = false; return result; public boolean uploadfile(string rwfiledir,string filepathname) boolean result=true; 字串8 string message = ; if (aftp != null) system.out.println(正在上传文件+filepathname+,请等待.); try strin
14、g fg =new string(subunsubfromsp); int index = stindexof(fg); string filename = filepathname.substring(index+1); file localfile = new file(filepathname) ; randomaccessfile sendfile = new randomaccessfile(filepathname,r); / sendfile.seek(0); /改名上传temp_ filename filename.substring(0,15)+temp_+filename.
15、substring(15,filename.length(); outs = aftp.put(filename); outputs = new dataoutputstream(outs); 字串8 while (sendfile.getfilepointer() sendfile.length() ) ch = sendfile.read(); = java做的比较完善的ftp上传下载文件服务器源码 outputs.write(ch); rename(filename.substring(15,filename.length(),filename.substring(20,filename
16、.length(); outs.close(); sendfile.close(); message = 上传+filepathname+文件胜利!; system.out.println(message); log(rwfiledir,message); catch(ioexception e) message = 上传+filepathname+文件失败!+e; system.out.println(message); log(rwfiledir,message); result = false ; 字串1 else result = false; return result; publi
17、c void rename(string oldname,string newname) /aftp.renameto(oldname,newname); file old = new file(oldname); /oldname file new = new file(newname); /newname /aftp.renameto(new); /boolean old.renameto(file newname); /system.out.println(old); /system.out.println(new); public static void delefile(string rwfiledir) /try java做的比较完善的ftp上传下载文件服务器源码 /取得readfile名目下的txt文件 string sdir = rwfiledir + subunsubfromsp; file fdir = new file(sdir); string filename = ; int j = f
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 林业课件模板
- Z世代2025年绿色出行消费趋势与市场分析报告
- Z世代2025年智能家居产品用户体验与市场前景研究报告
- 2024年版《手术室护理实践指南》练习题(附答案)
- 病原微生物实验室生物安全培训班考试题及答案
- 2025年电工安全应急试题及答案
- 海姆立克急救法题(附答案)
- 危险化学品生产安全事故应急演练方案及脚本(2篇)
- 十八项核心制度培训测试题(附答案)
- 全国仪器仪表制造理论模拟题库及答案
- 湘科版科学五年级上册教学计划教学设计及教学总结
- 《PRP配合左归丸治疗肝肾亏虚型膝骨关节炎的临床观察》
- 医疗公司考勤管理制度
- 2024建筑工程资料承包合同范本
- 《汽车电路知识与基本操作技能(第2版)》中职全套教学课件
- GB 21258-2024燃煤发电机组单位产品能源消耗限额
- DB34T 4379-2023 农村房地一体不动产确权登记技术规程
- 塔吊监控合同模板
- 贵州珍酒酿酒有限公司招聘笔试题库2024
- JG-T 225-2020 预应力混凝土用金属波纹管
- Welcome+unit +and+Expressions+单词讲解课件 【知识精讲精研】高中英语人教版必修第一册
评论
0/150
提交评论