计网课设报告ftp服务器端和客户端

上传人:大米 文档编号:545543931 上传时间:2023-10-27 格式:DOC 页数:13 大小:181.51KB
返回 下载 相关 举报
计网课设报告ftp服务器端和客户端_第1页
第1页 / 共13页
计网课设报告ftp服务器端和客户端_第2页
第2页 / 共13页
计网课设报告ftp服务器端和客户端_第3页
第3页 / 共13页
计网课设报告ftp服务器端和客户端_第4页
第4页 / 共13页
计网课设报告ftp服务器端和客户端_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《计网课设报告ftp服务器端和客户端》由会员分享,可在线阅读,更多相关《计网课设报告ftp服务器端和客户端(13页珍藏版)》请在金锄头文库上搜索。

1、课程设计任务书专业: 学号: 学生姓名(签名): 设计题目:利用Socket网络编程机制实现FTP服务器一、设计实验条件1208实验室二、设计任务及要求1. 利用Socket网络编程机制实现FTP服务器;2. 实现从客户端能够下载服务器端的文件;3. 实现能够从客户端上传到服务器端的文件;4. 实现客户端能够改变服务器端的当前目录;5. 实现查看当前服务器工作目录下的文件。三、设计报告的内容1. 设计题目与设计任务(设计任务书)设计题目:利用Socket编程实现FTP服务器设计要求:任选一门自己熟悉的程序设计语言,利用Socket网络编程机制实现FTP服务器。2. 前言(绪论)(设计的目的、意

2、义等)FTP以它所使用的协议:文件传输协议(File Transfer Protocol)来命名的。正如其名所示:协议的任务是从一台计算机将文件传送到另一台计算机,它与这两台计算机所处的位置、联系的方式、以及使用的操作系统无关。假设两台计算机能与FTP协议对话,并且能访问INTERNET,就可以用FTP软件的命令来传输文件。对于不同的操作系统具体操作上可能会有些细微差别,但是其基本的命令结构是相同的。FTP采用“客户机/服务器”方式,socket客户机与服务器之间的通信方式如图1所示。图1 socket通信模型 FTP(File Transfer Protocol),是文件传输协议的简称。用于

3、Internet上的控制文件的双向传输。同时,它也是一个应用程序。用户可以通过它把自己机器与世界各地所有运FTP协议的服务器相连,访问服务器上的资源和信息。FTP协议在TCP/IP协议栈中的位置如表1: 表1. TCP/IP协议栈HTTP FTP TELN SMTP DNS TFTP NMP应用层TCP UDP传输层IP互联网络层X25 ISDN LAN WLAN FDDI ATM网络接口层当启动FTP从远程计算机拷贝文件时,事实上启动了两个程序:一个本地机器上的FTP客户端程序,它向FTP服务器提出拷贝文件的请求。另一个是启动在远程计算机的上的FTP服务器程序,它响应请求把你指定的文件传送到

4、你的计算机中。FTP采用“客户端/服务器”方式,用户要在自己的本地计算机上安装FTP客户端程序。从根本上说,FTP协议就是在网络中各种不同的计算机之间按照TCP/IP协议来传输文件。FTP协议采用客户端/服务器(Client/Sever)模式,由FTP客户端程序和FTP服务器端程序组成。使用时,先启动FTP客户端程序与远程主机建立连接,然后向远程主机发出传输命令,远程主机在收到命令后就给予响应,并执行正确的命令。3. 设计主体(各部分设计内容、分析、结论等)(1) 下载文件这部分功能是用来实现客户端从服务器下载文件到本地的功能。这部分用的是get函数来实现。客户端代码如下:public voi

5、d get(String serName)System.out.println(get+54512);System.out.println(请输入目录:);trySocket s = new Socket(serName,8888);br = new BufferedReader(new InputStreamReader(System.in); String downFile = br.readLine(); dos = new DataOutputStream(new BufferedOutputStream(s.getOutputStream();dos.writeUTF(downFil

6、e);dos.flush(); dis = new DataInputStream(new BufferedInputStream(s.getInputStream(); int bufferSize = 8192; byte buf = new bytebufferSize; int passedlen = 0; long len = 0; String savePath = D:Backup我的文档Baidu; savePath = savePath+File.separator+dis.readUTF(); DataOutputStream fileOut = new DataOutpu

7、tStream( new BufferedOutputStream( new FileOutputStream(savePath); len = dis.readLong(); System.out.println(文件的长度为: + len + KB); System.out.println(开始接收文件!); while (true) int read = 0; if (dis != null) read = dis.read(buf); passedlen += read; if (read = -1) break; System.out.println(文件接收了 + (passedl

8、en * 100 / len) + %); fileOut.write(buf, 0, read); System.out.println(接收完成,文件存为 + savePath); fileOut.close(); catch(IOException e )trydis.close();dos.close();s.close();catch(IOException e1 )客户端运行结果截图如图2:图2. get 函数客户端运行结果服务器端get函数如下:public void get()System.out.println(get+1111);Socket s = null;trys =

9、 ss.accept();dis = new DataInputStream(new BufferedInputStream(s.getInputStream(); String filePath = dis.readUTF(); System.out.println(filePath); dos = new DataOutputStream(new BufferedOutputStream(s.getOutputStream(); File file = new File(filePath); dos.writeUTF(file.getName(); dos.flush(); dos.wri

10、teLong(file.length(); dos.flush(); dis = new DataInputStream(new BufferedInputStream(new FileInputStream(filePath); int BUFSIZE = 8192; byte buf = new byteBUFSIZE; while(true) int read = 0; if(dis != null) read = dis.read(buf); else System.out.println(no file founded!); break; if (read = -1) break;

11、dos.write(buf, 0, read); dos.flush(); catch(IOException e)System.out.println(asdfsssssssssss);finallytrydos.close();dis.close();s.close();catch(IOException e)服务器端get函数运行结果截图如图3:图3.get 函数服务器端运行结果(2) 上传文件上传文件实现从本地上传文件到服务器端。这部分功能用的是put函数来实现。客户端put函数代码如下:public void put(String serName)System.out.println

12、(put);Socket s = null;trys = new Socket (serName,8888);br = new BufferedReader(new InputStreamReader(System.in); String upFile = br.readLine(); dos = new DataOutputStream(new BufferedOutputStream(s.getOutputStream(); File file = new File(upFile); dos.writeUTF(file.getName(); dos.flush(); dos.writeLong(file.length(); dos.flush(); dis = new DataInputStream(new BufferedInputStream(new FileInputStream(upFile); int BUFSIZE = 8192; byte buf = new byteBUFSIZE; w

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号