文件传输协议有哪些
篇一:文件传输协议(FTP)
文件传输协议(FTP)
文件传输协议(File Transfer Protocol,FTP)是一个被广泛应用的协议,它使得 我们能够在网络上方便地传输文件。早期FTP并没有涉及安全问题,随着互连网应用的快速增长,人们对安全的要求也不断提高。本文在介绍了FTP协议的基本特征后,从两个方面探讨了FTP安全问题的解决方案:协议在安全功能方面扩展;协议自身的安全问题以及用户如何防范之。
1. 简介
1.1 FTP的一些特性
早期对FTP的定义指出,FTP是一个ARPA计算机网络上主机间文件传输的用户级协议。其主要功能是方便主机间的文件传输,并且允许在其他主机上进行方便的存储和文件处理。[BA72]而现在FTP的应用范围则是Internet。
根据FTP STD 9定义,FTP的目标包括:[PR85]1) 促进文件(程序或数据)的共享2) 支持间接或隐式地使用远程计算机3) 帮助用户避开主机上不同的4) 可靠并有效地传
1
输数据
关于FTP的一些其他性质包括:FTP可以被用户在终端使用,但通常是给程序使用的。FTP中主要采用了传输控制协议(Transmission Control Protocol,TCP)[PJ81],和Telnet 协议[PJ83]。
1.2 重要历史事件[PR85]
1971年,第一个FTP的RFC(RFC 114)由A.K. Bhushan在1971年提出,同时由MIT与 Harvard实验实现。
1972年,RFC 172 提供了主机间文件传输的一个用户级协议。
1973年2月,在长期讨论(RFC 265,RFC 294,RFC 354,RFC 385,RFC 430)后,出现了一个官方文档RFC 454。
1973年8月,出现了一个修订后的新官方文档 RFC 542。确立了FTP的功能、目标和基本模型。当时数据传输协议采用NCP。
1980年,由于底层协议从NCP改变为TCP,RFC 765 定义了采用TCP的FTP。
1985年,一个作用持续至今的官方文档RFC 959(STD 9)
出台。
1.3 FTP模型[PR85]
就模型而言,从1973年以来并没有什么变化。下图是FTP使用模型:
2
-------------|/---------\|
|| User || --------||Interface|<---| User ||\-------/| -------- ---------- ||| |/------\| FTP Commands |/----V----\| ||Server|<----------------| User || || PI || FTP Replies || PI || |\----/| |\-------/| | | | |||
-------- |/--V---\|Data|/----V----\| -------- | File |<---|Server|<----------------| User |<---| File | |System| || DTP || Connection || DTP || |System| -------- |\------/| |\---------/| -------- ---------- -------------
Server-FTP USER-FTP
注: 1. data connection 可以双向使用(双工) 2. data
connection 不需要一直存在.
图一 FTP使用模型 术语
User PI(user-protocol interpreter): 用户协议解释器
Server PI(Server-protocol interpreter): 服务协议解释器
control connection:控制连接Data connection:数据连接
FTP Commands:FTP命令。描述Data connection的参
数,文件操作类型FTP Replies:FTP命令
在图一描述的模型中,User PI创建control connection。
control connection遵从Telnet协议。在用户初始化阶段,标
准FTP命令被User PI生成并通过control connection 传到
服务器处理。Server PI将相应的标准FTP应答通过control
3
connection回传给User PI。数据传输由Data connection完
成。
User DTP 在特定端口监听,由Server DTP 用指定参数
初始化连接。
另一种情形是用户希望在两台非本地的主机上传递文件。
用户与两个服务器建立control connection,安排两个服务器
间的文件传输。下图描述了这样的模型。
Control------------ Control----------| User-FTP
|<-----------| | User-PI ||| | C ||V ------------V
---------------------------- | Server-FTP | Data Connection|
Server-FTP | | A|<----------------------| B| --------------
Port (A)Port (B) --------------
图二 服务器间交互模型
2.FTP协议的安全扩展[HL97]
2.1 一些安全地进行文件传输实践
a. 通过FTP传输预先被加密的文件 b. 通过E-mail传输
预先被加密的文件 c. 通过PEM消息
d. 通过使用Kerberos的rcp命令.
2.2 在RFC 2228 之前的FTP并不安全
虽然FTP采用 TELNET 协议执行connection control操
作,而且 TELNET 协议后来又增补了认证和加密选项,但
在RFC 1123 中禁止在connection control中进行 TELNET
4
选项协商。另外 TELNET 协议也没有提供完整性保护,而
且也没有data connection 的保护。
2.3 扩展命令
AUTH (Authentication/Security Mechanism),认证与安全
机制 ADAT (Authentication/Security Data),认证与安全数
据 PROT (Data Channel Protection Level),数据通道保护层
次 PBSZ (Protection Buffer Size),保护缓冲大小 CCC
(Clear Command Channel),清空命令通道
MIC (Integrity Protected Command),完整性保护命令
CONF (Confidentiality Protected Command), 保密保护命
令 ENC (Privacy Protected Command),私有性保护命令
一种新的返回类型(6yz)也被引入以保护返回值。
2.4 协议状态图
下图描述了在一个提高了安全性的FTP实现中认证和和
授权的
。方形的块表示客户端需要发出的命令的状态,
菱形的块表示服务器需要发出响应的状态。
,------------------, USER__\| Unauthenticated |________\ | /| (new connection) | /| | `------------------' | || | || AUTH | |V | |/ \ | | 4yz,5yz / \ 234 |
|<--------<-------------. | | \ / | | |\_/| | ||| | || 334 | | |V| | | ,--------------------,| | | | Need Security Data |<--. | || | `--------------------'| | | || | | | || ADAT | | | |V | | |
5
|/ \ | | | | 4yz,5yz / \ 335| | |
`<--------<-----------' | | \ / | | \_/ | ||| || 235| |V | | ,---------------. | |
,---| Authenticated |<--------'| |当客户与服务器 |
`---------------' | 完成了认证,如 || | 果存在完整性就
|| USER| 必须对命令进行 || | 完整性保护。CCC
||<-------------------' 命令可以用来放松 |V这个限
制。|/ \
| 4yz,5yz / \ 2yz
|<--------<-----------.| \ / |\_/|||| 3yz |V| ,---------------. | | Need Password | |
`---------------' |||| PASS |V|/ \| 4yz,5yz / \ 2yz |<--------<-----------|| \ / |\_/|||| 3yz |V| ,--------------.|
| Need Account || `--------------'|||| ACCT |V|/ \| 4yz,5yz / \ 2yz `<--------<-----------|\ / \_/ | | |||||||| || ||| |||| | | || || ||| ||
篇二:文件传输协议
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
6
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using System.Net.Sockets;
using System.IO;
namespace TestSocketServerHSTF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//不显示出dataGridView1的最后一行空白
dataGridView1.AllowUserToAddRows = false;
}
#region 定义变量
#endregion
#region 进入窗体即启动服务
private void Form1_Load(object sender, EventArgs e)
{
//开启接收线程
7
Thread TempThread = new Thread(new ThreadStart(this.StartReceive)); TempThread.Start();
}
#endregion
#region 功能函数
private void StartReceive()
{
//创建一个网络端点
IPEndPoint ipep = new IPEndPoint(IPAddress.Any,
int.Parse(2005));
//MessageBox.Show(IPAddress.Any);
//创建一个套接字
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
//绑定套接字到端口
server.Bind(ipep);
//开始侦听(并堵塞该线程)
server.Listen(10);
//确认连接
Socket client = server.Accept();
//获得客户端节点对象
IPEndPoint clientep =
8
(IPEndPoint)client.RemoteEndPoint;
//获得[文件名]
string SendFileName =
System.Text.Encoding.Unicode.GetString(TransferFiles.Rec
eiveVarData(client));
//MessageBox.Show(文件名 + SendFileName);
//获得[包的大小]
string bagSize =
System.Text.Encoding.Unicode.GetString(TransferFiles.Rec
eiveVarData(client));
//MessageBox.Show(包大小 + bagSize);
//获得[包的总数量]
int bagCount =
int.Parse(System.Text.Encoding.Unicode.GetString(Transfer
Files.ReceiveVarData(client))); //MessageBox.Show(包的总
数量 + bagCount);
//获得[最后一个包的大小]
string bagLast =
System.Text.Encoding.Unicode.GetString(TransferFiles.Rec
eiveVarData(client));
//MessageBox.Show(最后一个包的大小 + bagLast);
//创建一个新文件
9
FileStream MyFileStream = new FileStream(SendFileName, FileMode.Create,
FileAccess.Write);
//已发送包的个数
int SendedCount = 0;
while (true)
{
byte[] data = TransferFiles.ReceiveVarData(client);
if (data.Length == 0)
{
break;
}
else
{
SendedCount++;
//将接收到的数据包写入到文件流对象
MyFileStream.Write(data, 0, data.Length);
//显示已发送包的个数
//MessageBox.Show(已发送包个数
+SendedCount.ToString());}
}
//关闭文件流
10
MyFileStream.Close();
//关闭套接字
client.Close();
//填加到dgv里
//文件大小,IP,已发送包的个数,文件名,包的总量,
最后一个包的大小 this.dataGridView1.Rows.Add(bagSize,
clientep.Address, SendedCount, SendFileName, bagCount,
bagLast);
//MessageBox.Show(文件接收完毕!);
}
#endregion
#region拦截Windows消息,关闭窗体时执行
protected override void WndProc(refMessage m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE) {//捕捉关闭窗体消息
//Userclickedclosebutton
//this.WindowState = FormWindowState.Minimized;//把
右上角红叉关闭按钮变最小化
ServiceStop();
11
}
base.WndProc(refm);
}
#endregion
#region 停止服务
//停止服务
private void ServiceStop()
{
try
{
}
catch { }
try
{
}
catch { }
}
#endregion
}
}
客户端用来发送文件,选择文件后点发送按钮发送文件
客户端代码:
12
////////////////////////////////////////////////////////////////////////////////
//title: 点对点文件传输程序
////////////////////////////////////////////////////////////////////////////////
//////////////////////////Begin-发送端//////////////////////////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace 发送端
{
/// <summary
/// Form1 的摘要说明。
/// </summary
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
13
private System.Windows.Forms.OpenFileDialog openFileDialog1;private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox3;(转 载
于:wWW.xlTkWJ.Com 小 龙文 档 网:文件传输协议有哪
些) private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox4; //
篇三:文件传输协议(FTP)
《网络协议》实验报告
实 验 名称:文件传输协议(FTP)
组别机器号:第六组主机B
班级:网络13-3班
学号:1320020306
姓名:黄腾飞
指 导 教师:陈虹
成绩:
1
2
14
3
4
5
相关热词搜索:
15