FTP 协议实现程序.doc
《FTP 协议实现程序.doc》由会员分享,可在线阅读,更多相关《FTP 协议实现程序.doc(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-作者xxxx-日期xxxxFTP 协议实现程序【精品文档】课题:FTP 协议实现程序 选题1 课程设计目的本课程设计设计需要编写程序,对FPT 协议有非常清楚的认识2 课程设计要求完成应用层协议的基本工作模型,规划客户,服务器的基本结构与模块组成,完成应用层协议设计,网络应用软件设计方法与编程。 FTP功能模块及原理1 FPT基本原理FTP使用两条Tcp连接来完成文件传输,控制连接与数据连接。控制连接用与传输控制,数据连接用于数据传输。在服务器启动后,服务器会在端口21等待客户的连接请求,有用户需要传输文件时,客户与服务器的端口21建立一个控制连接,用来传送客户的命令和服务器的应答,是连接一
2、直保持到客户与服务器通信结果为止。当客户发出数据传输命令时,服务器会主动与客户建立数据连接,并与其进行数据交换。2 FTP功能模块 FTP功能模块及FTP连接1 程序功能的介绍1)FTP连接 进行FTP连接,首先要给出目的计算机的名称或地址,当连接到信宿机后,一般要进行登录,在检验用户ID号和口令后,连接才得以建立,某些系统也允许用户进行匿名登录。与在所有的多用户系统中一样,对于 同一目录或文件,不同的用户拥有不同的权限,所以在使用过程中,需要验证权限。2)文件传输方式 FTP可用多种格式传输文件,通常 由系统定,大多数系统(包括UNIX系统)只有两种模式:文本模式和二进制模式。文件传输器使用
3、ASCII码,并由回车键和换行符分开,而二进制不用转换或格式化就可以传字符,二进制模式比文本模式更快,并且可以传输所有ASCII值,所以系统管理而一般将FTP设置成二进制模式。3)断开连接 比较流行的FTP软件,一般有取消传输的指令和重建连接的指令,本程序只有断开连接的指令。 以上三方面是本程序的主要功能,事实上还不够完善。例如:显示消息,更改端口等。2 程序设计1)设计界面 如图61所示本程序采取单一界面。界面内的控件采用控件为Command Button,Line,TextBox,Option Button,Tree View,DirListBox,FileList Box和Drive L
4、ist Box。以下是主要控件的属性列表: 程序主界面控件布置对象属性设置值fmVBFTPJR FormCaptionVbFTPCmdInternetOpen CommandButtonCaptionStart Internet SessionTxtProxy TextBox所有属性默认CmdConnect CommandButtonCaptionConnectChkPassive CheckBoxCaptionPassive FTP syntaxCmdDisconnect CommandButtonCaptionDisconnectCmdClosehOpen CommandButtonCap
5、tionClose Internet SessionTree View1 Tree View 所有属性默认OptBin OptionButtonCaptionBinaryoptAscii OptionButtonCaptionAsciicmdGet CommandButtonCaptionDownloadcmdPut CommandButtonCaptionUploadDrive1 DriveListBox所有属性默认Dir1 DirListBox所有属性默认File1 FileListBox所有属性默认TxtServer TextBoxCaptionInput IP heretxtUser
6、TextBox所有属性默认txtPassword TextBoxPasswordchar* 控制对象属性列表3 程序Attribute VB_Name = modWinInetOption ExplicitDeclare Function GetProcessHeap Lib kernel32 () As LongDeclare Function HeapAlloc Lib kernel32 (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As LongDeclare Function HeapFree L
7、ib kernel32 (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As LongPublic Const HEAP_ZERO_MEMORY = &H8Public Const HEAP_GENERATE_EXCEPTIONS = &H4Declare Sub CopyMemory1 Lib kernel32 Alias RtlMoveMemory ( _ hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)Declare Sub CopyMemor
8、y2 Lib kernel32 Alias RtlMoveMemory ( _ hpvDest As Long, hpvSource As Any, ByVal cbCopy As Long)Public Const MAX_PATH = 260Public Const NO_ERROR = 0Public Const FILE_ATTRIBUTE_READONLY = &H1Public Const FILE_ATTRIBUTE_HIDDEN = &H2Public Const FILE_ATTRIBUTE_SYSTEM = &H4Public Const FILE_ATTRIBUTE_DI
9、RECTORY = &H10Public Const FILE_ATTRIBUTE_ARCHIVE = &H20Public Const FILE_ATTRIBUTE_NORMAL = &H80Public Const FILE_ATTRIBUTE_TEMPORARY = &H100Public Const FILE_ATTRIBUTE_COMPRESSED = &H800Public Const FILE_ATTRIBUTE_OFFLINE = &H1000Type FILETIME dwLowDateTime As Long dwHighDateTime As LongEnd TypeTy
10、pe WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14End TypePublic Const ERROR_NO_MOR
11、E_FILES = 18Public Declare Function InternetFindNextFile Lib wininet.dll Alias InternetFindNextFileA _ (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long Public Declare Function FtpFindFirstFile Lib wininet.dll Alias FtpFindFirstFileA _(ByVal hFtpSession As Long, ByVal lpszSearchFile As S
12、tring, _ lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As LongPublic Declare Function FtpGetFile Lib wininet.dll Alias FtpGetFileA _(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dw
13、FlagsAndAttributes As Long, _ ByVal dwFlags As Long, ByVal dwContext As Long) As BooleanPublic Declare Function FtpPutFile Lib wininet.dll Alias FtpPutFileA _(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, ByVal dwContext As Long)
14、 As BooleanPublic Declare Function FtpSetCurrentDirectory Lib wininet.dll Alias FtpSetCurrentDirectoryA _ (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As BooleanPublic Declare Function InternetOpen Lib wininet.dll Alias InternetOpenA _(ByVal sAgent As String, ByVal lAccessType As Long,
15、 ByVal sProxyName As String, _ByVal sProxyBypass As String, ByVal lFlags As Long) As LongPublic Const scUserAgent = vb wininetPublic Const INTERNET_OPEN_TYPE_PRECONFIG = 0Public Const INTERNET_OPEN_TYPE_DIRECT = 1Public Const INTERNET_OPEN_TYPE_PROXY = 3Public Const INTERNET_INVALID_PORT_NUMBER = 0P
16、ublic Const FTP_TRANSFER_TYPE_ASCII = &H1Public Const FTP_TRANSFER_TYPE_BINARY = &H1Public Const INTERNET_FLAG_PASSIVE = &H8000000Public Declare Function InternetConnect Lib wininet.dll Alias InternetConnectA _(ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer
17、, _ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, _ByVal lFlags As Long, ByVal lContext As Long) As Long Public Const ERROR_INTERNET_EXTENDED_ERROR = 12003Public Declare Function InternetGetLastResponseInfo Lib wininet.dll Alias InternetGetLastResponseInfoA ( _ lpdwErr
18、or As Long, _ ByVal lpszBuffer As String, _ lpdwBufferLength As Long) As BooleanPublic Const INTERNET_DEFAULT_FTP_PORT = 21Public Const INTERNET_DEFAULT_GOPHER_PORT = 70Public Const INTERNET_DEFAULT_HTTP_PORT = 80Public Const INTERNET_DEFAULT_HTTPS_PORT = 443Public Const INTERNET_DEFAULT_SOCKS_PORT
19、= 1080Public Const INTERNET_OPTION_CONNECT_TIMEOUT = 2Public Const INTERNET_OPTION_RECEIVE_TIMEOUT = 6Public Const INTERNET_OPTION_SEND_TIMEOUT = 5Public Const INTERNET_OPTION_USERNAME = 28Public Const INTERNET_OPTION_PASSWORD = 29Public Const INTERNET_OPTION_PROXY_USERNAME = 43Public Const INTERNET
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- FTP 协议实现程序 协议 实现 程序
限制150内