FTP 协议实现程序.doc

上传人:豆**** 文档编号:33479414 上传时间:2022-08-11 格式:DOC 页数:23 大小:251.50KB
返回 下载 相关 举报
FTP 协议实现程序.doc_第1页
第1页 / 共23页
FTP 协议实现程序.doc_第2页
第2页 / 共23页
点击查看更多>>
资源描述

《FTP 协议实现程序.doc》由会员分享,可在线阅读,更多相关《FTP 协议实现程序.doc(23页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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

20、_OPTION_PROXY_PASSWORD = 44Public Const INTERNET_SERVICE_FTP = 1Public Const INTERNET_SERVICE_GOPHER = 2Public Const INTERNET_SERVICE_HTTP = 3Public Declare Function HttpOpenRequest Lib wininet.dll Alias HttpOpenRequestA _(ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As Strin

21、g, ByVal sVersion As String, _ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As LongPublic Const INTERNET_FLAG_RELOAD = &H80000000Public Const INTERNET_FLAG_KEEP_CONNECTION = &H400000Public Const INTERNET_FLAG_MULTIPART = &H200000Public Const GENERIC

22、_READ = &H80000000Public Const GENERIC_WRITE = &H40000000Public Declare Function HttpSendRequest Lib wininet.dll Alias HttpSendRequestA (ByVal _hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As _String, ByVal lOptionalLength As Long) As IntegerPublic De

23、clare Function HttpQueryInfo Lib wininet.dll Alias HttpQueryInfoA _(ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, _ByRef lBufferLength As Long, ByRef lIndex As Long) As IntegerPublic Const HTTP_QUERY_CONTENT_TYPE = 1Public Const HTTP_QUERY_CONTENT_LENGTH = 5Public Const

24、 HTTP_QUERY_EXPIRES = 10Public Const HTTP_QUERY_LAST_MODIFIED = 11Public Const HTTP_QUERY_PRAGMA = 17Public Const HTTP_QUERY_VERSION = 18Public Const HTTP_QUERY_STATUS_CODE = 19Public Const HTTP_QUERY_STATUS_TEXT = 20Public Const HTTP_QUERY_RAW_HEADERS = 21Public Const HTTP_QUERY_RAW_HEADERS_CRLF =

25、22Public Const HTTP_QUERY_FORWARDED = 30Public Const HTTP_QUERY_SERVER = 37Public Const HTTP_QUERY_USER_AGENT = 39Public Const HTTP_QUERY_SET_COOKIE = 43Public Const HTTP_QUERY_REQUEST_METHOD = 45Public Const HTTP_STATUS_DENIED = 401Public Const HTTP_STATUS_PROXY_AUTH_REQ = 407Public Const HTTP_QUER

26、Y_FLAG_REQUEST_HEADERS = &H80000000Public Const HTTP_QUERY_FLAG_NUMBER = &H20000000Public Declare Function InternetReadFile Lib wininet.dll _(ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, _lNumberOfBytesRead As Long) As IntegerPublic Declare Function InternetWriteFile

27、Lib wininet.dll _ (ByVal hFile As Long, ByVal sBuffer As String, _ ByVal lNumberOfBytesToRead As Long, _ lNumberOfBytesRead As Long) As IntegerPublic Declare Function FtpOpenFile Lib wininet.dll Alias _ FtpOpenFileA (ByVal hFtpSession As Long, _ ByVal sFileName As String, ByVal lAccess As Long, _ By

28、Val lFlags As Long, ByVal lContext As Long) As LongPublic Declare Function FtpDeleteFile Lib wininet.dll _ Alias FtpDeleteFileA (ByVal hFtpSession As Long, _ ByVal lpszFileName As String) As BooleanPublic Declare Function InternetSetOption Lib wininet.dll Alias InternetSetOptionA _(ByVal hInternet A

29、s Long, ByVal lOption As Long, ByRef sBuffer As Any, ByVal lBufferLength As Long) As IntegerPublic Declare Function InternetSetOptionStr Lib wininet.dll Alias InternetSetOptionA _(ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As IntegerPublic D

30、eclare Function InternetCloseHandle Lib wininet.dll _(ByVal hInet As Long) As IntegerPublic Declare Function InternetQueryOption Lib wininet.dll Alias InternetQueryOptionA _(ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long) As IntegerPublic Const INTE

31、RNET_OPTION_VERSION = 40Public Type tWinInetDLLVersion lMajorVersion As Long lMinorVersion As LongEnd TypePublic Declare Function HttpAddRequestHeaders Lib wininet.dll Alias HttpAddRequestHeadersA _(ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, _ByVal lModifiers

32、 As Long) As IntegerPublic Const HTTP_ADDREQ_FLAG_ADD_IF_NEW = &H10000000Public Const HTTP_ADDREQ_FLAG_ADD = &H20000000Public Const HTTP_ADDREQ_FLAG_REPLACE = &H80000000Object = 6B7E6392-850A-101B-AFC0-4210102A8DA7#1.3#0; COMCTL32.OCXBegin VB.Form fmVBFTPJR Caption = vbFTP ClientHeight = 5640 Client

33、Left = 60 ClientTop = 345 ClientWidth = 8715 Icon = fmVBFTPJR.frx:0000 LinkTopic = Form1 ScaleHeight = 5640 ScaleWidth = 8715 StartUpPosition = 3 Begin VB.OptionButton optAscii Height = 195 Left = 3600 TabIndex = 20 Top = 3120 Width = 1095 End Begin VB.OptionButton optBin Caption = Binary Height = 3

34、75 Left = 3600 TabIndex = 19 Top = 2640 Width = 855 End Begin VB.CommandButton cmdPut Caption = upload Height = 495 Left = 3480 TabIndex = 18 Top = 3840 Width = 975 End Begin VB.CommandButton cmdGet Caption = download Height = 495 Left = 3480 TabIndex = 17 Top = 3360 Width = 975 End Begin ComctlLib.

35、TreeView TreeView1 Height = 2655 Left = 360 TabIndex = 16 Top = 2640 Width = 3015 _ExtentX = 5318 _ExtentY = 4683 _Version = 327682 Style = 7 Appearance = 1 End Begin VB.FileListBox File1 Height = 1890 Left = 6960 TabIndex = 15 Top = 3120 Width = 1575 End Begin VB.DirListBox Dir1 Height = 2115 Left

36、= 5040 TabIndex = 14 Top = 3120 Width = 1695 End Begin VB.DriveListBox Drive1 Height = 315 Left = 5040 TabIndex = 13 Top = 2640 Width = 3495 End Begin VB.CheckBox chkPassive Caption = Passive FTP syntax Height = 255 Left = 3120 TabIndex = 12 Top = 1800 Width = 2175 End Begin VB.CommandButton cmdDisc

37、onnect Caption = Disconnect Height = 495 Left = 5760 TabIndex = 11 Top = 1680 Width = 1815 End Begin VB.CommandButton cmdConnect Caption = Connect Height = 495 Left = 360 TabIndex = 10 Top = 1680 Width = 2175 End Begin VB.TextBox txtPassword Height = 375 IMEMode = 3 DISABLE Left = 7200 PasswordChar

38、= * TabIndex = 9 Top = 1080 Width = 1095 End Begin VB.TextBox txtUser Height = 375 Left = 4680 TabIndex = 7 Top = 1080 Width = 1095 End Begin VB.TextBox txtServer Height = 375 Left = 1680 TabIndex = 4 Text = Input IP here Top = 1080 Width = 1455 End Begin VB.CommandButton cmdClosehOpen Caption = Clo

39、se Internet Session Height = 495 Left = 2280 TabIndex = 3 Top = 240 Width = 1935 End Begin VB.TextBox txtProxy Height = 435 Left = 7200 TabIndex = 1 Top = 240 Width = 1095 End Begin VB.CommandButton cmdInternetOpen Caption = Start Internet Session Height = 495 Left = 240 TabIndex = 0 Top = 240 Width = 1935 End Begin ComctlLib.ImageList Ima

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁