![文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/13/61bc9b13-f3da-4160-be7b-09047b7acb16/61bc9b13-f3da-4160-be7b-09047b7acb161.gif)
![文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/13/61bc9b13-f3da-4160-be7b-09047b7acb16/61bc9b13-f3da-4160-be7b-09047b7acb162.gif)
![文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/13/61bc9b13-f3da-4160-be7b-09047b7acb16/61bc9b13-f3da-4160-be7b-09047b7acb163.gif)
![文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/13/61bc9b13-f3da-4160-be7b-09047b7acb16/61bc9b13-f3da-4160-be7b-09047b7acb164.gif)
![文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-3/13/61bc9b13-f3da-4160-be7b-09047b7acb16/61bc9b13-f3da-4160-be7b-09047b7acb165.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、課程設(shè)計(jì)課程名稱計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)題目名稱文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)學(xué)生學(xué)院專業(yè)班級(jí)_學(xué)號(hào)學(xué)生姓名指導(dǎo)教師2010年1月5日設(shè)計(jì)摘要關(guān)鍵詞:SOCKET程,F(xiàn)TPclient/server程序摘要:本課程設(shè)計(jì)包含了文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)文件傳送是各種計(jì)算機(jī)網(wǎng)絡(luò)實(shí)現(xiàn)的基本功能,文件傳送協(xié)議是一種最基本的應(yīng)用層協(xié)議按照客戶/服務(wù)器的模式進(jìn)行工作,提供交互式的訪問(wèn),是INTERNET使用最廣泛的協(xié)議之一。文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)建立在計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)環(huán)境TCP/IP網(wǎng)絡(luò)體系結(jié)構(gòu)之上,使用socket編程接口編寫(xiě)兩個(gè)程序,分別為客戶程序(client.c)和服務(wù)器程序(server.。,實(shí)現(xiàn)
2、下述命令功能:get,put,pwd,dir,cd,?,quit等,利用了已有網(wǎng)絡(luò)環(huán)境設(shè)計(jì)并實(shí)現(xiàn)簡(jiǎn)單應(yīng)用層協(xié)議。本設(shè)計(jì)包括了具體設(shè)計(jì)任務(wù),基本思路及所涉及的相關(guān)理論,設(shè)計(jì)流程圖,調(diào)試過(guò)程中出現(xiàn)的問(wèn)題及相應(yīng)解決辦法,實(shí)驗(yàn)運(yùn)行結(jié)果,核心程序,個(gè)人體會(huì)及建議等。目錄1、文件傳輸協(xié)議的簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)181. 1具體設(shè)計(jì)任務(wù)181.2 基本思路及所涉及的相關(guān)理論181.2.1 基本思路182.2.2相關(guān)理論181.3 設(shè)計(jì)流程圖191.4 實(shí)驗(yàn)運(yùn)行情況191.5 核心程序221.5.1 服務(wù)器(sever)程序221.5.2 客戶(client)程序291.6 心得體會(huì)37參考文獻(xiàn)382、文件傳輸協(xié)議的
3、簡(jiǎn)單設(shè)計(jì)與實(shí)現(xiàn)2. 1具體設(shè)計(jì)任務(wù)計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)環(huán)境建立在TCP/IP網(wǎng)絡(luò)體系結(jié)構(gòu)之上。各計(jì)算機(jī)除了安裝TCP/IP軟件外,還安裝了TCP/IP開(kāi)發(fā)系統(tǒng)。實(shí)驗(yàn)室各計(jì)算機(jī)具備Windows環(huán)境中套接字socket的編程接口功能,可為用戶提供全網(wǎng)范圍的進(jìn)程通信功能。本實(shí)驗(yàn)要求利用這些功能,設(shè)計(jì)和實(shí)現(xiàn)一個(gè)簡(jiǎn)單的文件傳送協(xié)議。用socket編程接口編寫(xiě)兩個(gè)程序,分別為客戶程序(client.c)和服務(wù)器程序(server.。,該程序應(yīng)能實(shí)現(xiàn)下述命令功能:get::取遠(yuǎn)方的一個(gè)文件put:傳給遠(yuǎn)方一個(gè)文件pwd:顯示遠(yuǎn)主當(dāng)前目錄dir:列出遠(yuǎn)方當(dāng)前目錄cd:改變遠(yuǎn)方當(dāng)前目錄?:顯示你提供的命令quit:
4、退出返回2.2 基本思路及所涉及的相關(guān)理論2.2.1 基本思路設(shè)計(jì)程序使客戶端連接的時(shí)候,服務(wù)器將會(huì)向客戶端發(fā)回一條消息告知它的IP地址,然后關(guān)閉連接并繼續(xù)接收端口的連接。建立各個(gè)命令功能對(duì)應(yīng)的函數(shù),發(fā)送請(qǐng)求,等待服務(wù)器端的服務(wù)。服務(wù)器端初始化WinSock,創(chuàng)建SOCKET,獲取主機(jī)信息,并對(duì)客戶端進(jìn)行會(huì)話,發(fā)送回復(fù)訊息給客戶端,響應(yīng)完畢后關(guān)閉連接,釋放WinSock。2.2.2 相關(guān)理論文件傳送是各種計(jì)算機(jī)網(wǎng)絡(luò)都實(shí)現(xiàn)的基本功能,文件傳送協(xié)議是一種最基本的應(yīng)用層協(xié)議按照客戶/服務(wù)器的模式進(jìn)行工作,提供交互式的訪問(wèn),是INTERNET使用最廣泛的協(xié)議之一。計(jì)算機(jī)網(wǎng)絡(luò)實(shí)驗(yàn)環(huán)境建立在TCP/IP網(wǎng)
5、絡(luò)體系結(jié)構(gòu)之上。各計(jì)算機(jī)除了安裝TCP/IP軟件外,還安裝了TCP/IP開(kāi)發(fā)系統(tǒng)。實(shí)驗(yàn)室各計(jì)算機(jī)具備Windows環(huán)境中套接字socket的編程接口功能,可為用戶提供全網(wǎng)范圍的進(jìn)程通信功能。本設(shè)計(jì)利用這些功能,設(shè)計(jì)和實(shí)現(xiàn)一個(gè)簡(jiǎn)單的文件傳送協(xié)議。用socket編程接口編寫(xiě)兩個(gè)程序,分別為客戶程序(client.c)和服務(wù)器程序(server.。2.3 設(shè)計(jì)流程圖2.4 實(shí)驗(yàn)運(yùn)行情況服務(wù)器端運(yùn)行,默認(rèn)自動(dòng)啟動(dòng)監(jiān)聽(tīng),情況如下圖:4服務(wù)器©Q停止監(jiān)聽(tīng)服第器g222.200120.10Z11000狀態(tài):正在蔡聽(tīng)端口11000.服務(wù)如果關(guān)閉監(jiān)聽(tīng),效果如下圖:客服端運(yùn)行,如下圖:A客,1網(wǎng)同百&g
6、t;4iM.inoMQ:isogo洼最、裝上百保存位餐I文怦名五修改日期下物風(fēng)列串京怦石zt刁:F«tJ祀虎BSBntiRl:io10-01-utgroif輸入服務(wù)器端的IP和端口號(hào)進(jìn)行連接,效果如圖:卜面設(shè)置文件保存位置,如圖:客干制aSE8酎開(kāi)丁顯上倍身存位置T222.SOD.12J,1021端口:11J0C文件右,'返回上層<an.igQLinwI。,QQQDdumlq蒞ITeqREGCUESystemUmLiurqJrifox'H'o.-taocei.*qTt或05.tirnTTAdilRefjjhphGe小八行1卬注.HL2,.u£a
7、vPulFiIcSI-JLufiJlmvn*r*-0|3lvnvu.'s.-l.舊Iwnvir-!logWE*4r.下我隊(duì)列!文件名大小待四日期融覽文件夾zaz:sL:3B48十本出量增£1本地磁盤(pán)I:)Kwac.mDcric-ni£SicPrcigj3ii>FilesTcpUcwnl0acLL,pYirtdcws7新建工作衣-LE&0143-L31L:59:44-IS1145-U41L:1O:O&-2602.27144812:uef-UB-030L:ES:ES-LT03ST42LI03:3:7:ly47Qt:01!5TI-zidcizm希拜文
8、件*®和定弧涓弓運(yùn)徨主松%200.1.1021100隋接翊療I"下我接國(guó)12K上怯速度:&bMKk下面演示上傳一個(gè)視頻文件,然后再下載下來(lái),其中上傳過(guò)程的進(jìn)度信息:與超程主機(jī)班工200.1ZB,UOI11??谂e鼻國(guó)(功(H上傳完成后的效果圖:2.5核心程序2.5.1服務(wù)器(server)程序如下usingusingSystem;System.Collections.GenericusingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Net;usingSystem.Net.Sockets
9、;usingSystem.IO;usingSystem.Windows.Forms;namespaceTCP文件傳輸_服務(wù)器(classWorkThread(bytebuffer;intbufferSize=4096;Threadmythread;Sockethandler;publicWorkThread(SocketworkSocket)(handler=workSocket;buffer=newbytebufferSize;mythread=newThread(BeginCommunication);publicvoidStart()(mythread.Start();publicvoi
10、dAbort()(mythread.Abort();privatevoidBeginCommunication()while(true)/從客戶端接收數(shù)據(jù),直到連接斷開(kāi)try(intreCount=handler.Receive(buffer);stringinsStr=Encoding.BigEndianUnicode.GetString(buffer,0,reCount);if(insStr.Substring(0,4)="name")/收到下文件請(qǐng)求(stringfileName=insStr.Substring(5,insStr.Length-5);SendFile
11、(fileName,handler);elseif(insStr.Substring(0,4)="boot")/收到獲取根目錄請(qǐng)求(stringlistStr=GetFileNames("F:",false);SendString(handler,listStr);elseif(insStr.Substring(0,4)="path")/收到獲取指定目錄內(nèi)容請(qǐng)求(stringpath=insStr.Substring(5,insStr.Length-5);stringlistStr=GetFileNames(path,false);S
12、endString(handler,listStr);elseif(insStr.Substring(0,4)="Queu")/獲取下載文件夾請(qǐng)求,回復(fù)完整文件名列表(stringpath=insStr.Substring(5,insStr.Length-5);stringlistStr=GetFileNames(path,true);SendString(handler,listStr);elseif(insStr.Substring(0,4)="upld")/收到上傳文件請(qǐng)求(stringreFileName=insStr.Substring(5,i
13、nsStr.Length-5);"quit")/收到斷開(kāi)連LoadFile(reFileName,handler);elseif(insStr.Substring(0,4)=接命令HostQuit();break;)catchHostQuit();break;)privatevoidLoadFile(stringreFileName,Sockethandler)tryFileStreamfs=newFileStream(reFileName,FileMode.CreateFileAccess.Write);handler.Receive(buffer,8,SocketFla
14、gs.None);/接收文件大小longfilesize=BitConverter.ToInt64(buffer,0);longreceiveCount=0;while(receiveCount<filesize)/接收文件intreadcount=handler.Receive(buffer,bufferSize,SocketFlags.None);fs.Write(buffer,0,readcount);receiveCount+=readcount;fs.Close();catchHostQuit();privatevoidSendFile(stringfileNmae,Socke
15、thandler)tryFileStreamfs=newFileStream(fileNmae,FileMode.Open,FileAccess.Read);longsize=fs.Length;bytebysize=BitConverter.GetBytes(size);handler.Send(bysize,8,SocketFlags.None);/發(fā)送文件大小BinaryReaderbr=newBinaryReader(fs);intsendcount=0;while(sendcount<size)/發(fā)送文件(intreadcount=br.Read(buffer,0,buffer
16、Size);sendcount+=readcount;handler.Send(buffer,readcount,SocketFlags.None);catch(HostQuit();privatevoidHostQuit()(GlobalValues.canControl.WaitOne(););GlobalValues.canControl.Release();if(handler.Connected=true)(handler.Shutdown(SocketShutdown.Both);handler.Close();privatevoidSendString(Sockethandler
17、,stringlistStr)(byte口list=Encoding.BigEndianUnicode.GetBytes(listStrbytelistcountbuffer=BitConverter.GetBytes(Convert.ToInt64(list.Length);try(handler.Send(listcountbuffer,8,SocketFlags.None);/發(fā)送列表大小intsendcount=0;while(sendcount<list.Length)/發(fā)送列表(if(sendcount+bufferSize<list.Length)/不是最后一次(in
18、ti=handler.Send(list,sendcount,bufferSize,SocketFlags.None);sendcount+=i;elseinti=handler.Send(list,sendcount,list.Lengthsendcount,SocketFlags.None);/發(fā)送最后一次sendcount+=i;)catch(Exceptione)MessageBox.Show("連接斷開(kāi).");)/fileOnly=true則獲取指定目錄及子目錄內(nèi)所有文件信息,fileOnly=false則獲取指定目錄文件信息及文件夾信息privatestring
19、GetFileNames(stringpath,boolfileOnly)stringlistStr=string.Empty;DirectoryInfodrct=newDirectoryInfo(path);foreach(FileSystemInfofsiindrct.GetFileSystemInfos()if(fsiisFileInfo)/文件FileInfofi=(FileInfo)fsi;listStr+=fi.FullName;listStr+="n"if(fi.Length<1024)stringsizeStr=fi.Length.ToString()
20、+"字節(jié)"listStr+=sizeStr;)elseif(fi.Length<1024*1024)doubletemp=Convert.ToDouble(fi.Length)/1024;stringsizeStr=string.Format("0:F1”,temp)+"KB"listStr+=sizeStr;elseif(fi.Length<1024*1024*1024)doubletemp=Convert.ToDouble(fi.Length)/1024/1024;stringsizeStr=string.Format(&quo
21、t;0:F1",temp)+"MB"listStr+=sizeStr;elsedoubletemp=Convert.ToDouble(fi.Length)/1024/1024/1024;stringsizeStrstring.Format("0:F1”,temp)"GB"listStr+=sizeStr;hh:mm:ss"hh:mm:ss"););listStrlistStrlistStrelseif(fsi+=+=+=if(fileOnlylistStr"'n"fi.LastWrite
22、Time.ToString("yyyy-MM-ddelse"n"isDirectoryInfo+=GetFileNames(fsi.FullName,true);returnpublic(服務(wù)器()/文件夾DirectoryInfolistStr+=di.listStr+="n"listStr+="dir"listStr+="n"listStr+=di.listStr+="n"LastWriteTime.ToStringdi=(DirectoryInfoFullName;listStr
23、)fsi("yyyy-MM-ddInitializeComponent();Control.CheckForIllegalCrossThreadCallsfalse;stringHostNameIPHostEntryIpEntryDns.GetHostName();=Dns.GetHostEntry/得到主機(jī)名(HostName);/得到主機(jī)IPstringstrlPAddr=IpEntry.AddressList0.ToString();tsTxb_IPAdd.Text=strIPAddrhostIPAddress=IPAddress.Parse(strIPAddr);Server
24、=newIPEndPoint(hostIPAddress,Convert.ToInt32(tsTxb_Port.Text);sock=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);sock.Bind(Server);sock.Listen(10);stringstr="正在監(jiān)聽(tīng)端口"+tsTxb_Port.Text+"."tsLbl_Status.Text="狀態(tài):"+str;AcceptTh=newThread(ThAccept);A
25、cceptTh.Start();/開(kāi)始監(jiān)聽(tīng)端口/下面是監(jiān)聽(tīng)和停止監(jiān)聽(tīng)的按鈕事件privatevoidbtn_Start_Click(objectsender,EventArgse)tsBtn_Start.Enabled=false;tsBtn_Stop.Enabled=true;Server=newIPEndPoint(hostIPAddress,Convert.ToInt32(tsTxb_Port.Text);sock=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);sock.Bind(Serv
26、er);sock.Listen(10);stringstr="正在監(jiān)聽(tīng)端口"+tsTxb_Port.Text+tsLbl_Status.Text="狀態(tài):"+str;AcceptTh=newThread(ThAccept);AcceptTh.Start();privatevoidtsBtn_StarttsBtn_Stoptrybtn_stop_Click(object.Enabled=true;.Enabled=false;sender,EventArgse)Both);sock.Shutdown(SocketShutdowncatchsock.Clos
27、e();tsLbl_Status.Text="狀態(tài):已停止監(jiān)聽(tīng)2.5.2客戶(client)程序/MyThread.cs中的實(shí)現(xiàn)usingusingSystem;System.Collections.GenericusingSystem.Linq;usingSystem.Text;usingSystem.IO;usingSystem.Net.Sockets;usingSystem.Threading;usingSystem.Windows.Forms;namespace客戶端TCP文件傳輸(publicclassmyThread(ThreaddownloadTh;Threaduplo
28、adTh;SocketwordSocket;stringfileName;stringsavePath;byte口buffer;constintbufferSize=4096;ToolStripProgressBartspBar;ToolStripStatusLabelspeed;intstartTime=0;longreceivecount=0;longsendCount=0;intupOrDown=1;/指示上傳或下載SavePathSpeed)System.Windows.Forms.Timertimer1=newSystem.Windows.Forms.Timer();publicmy
29、Thread(SocketworkSock,stringFileName,stringrefToolStripProgressBarTspBar,refToolStripStatusLabel(wordSocket=workSock;fileName=FileName;savePath=SavePath;buffer=newbytebufferSize;downloadTh=newThread(newThreadStart(DownloaduploadTh=newThread(newThreadStart(Upload);tspBar=TspBar;speed=Speed;FileName,r
30、efpublicmyThread(SocketworkSock,stringToolStripProgressBarTspBar,refToolStripStatusLabelSpeed)wordSocketworkSock;fileNamebufferdownloadThFileName;newbytebufferSize;=newThread(newThreadStartuploadThnewThread(newThreadStart(Download(Upload););Convert+stringtspBarspeedTspBar;Speed;publicvoidStartDownlo
31、ad()upOrDowndownloadTh=1;.Start();timer1timer1timer1.Enabledtrue.Interval=100;.Tick+=newEventHandler(timer1_Tick);startTimetimer1=System.Environment.Start();publicvoidStartUpload()void.TickCountupOrDownuploadTh=0;.Starttimer1timer1timer1.Enabled.Interval.Tick+=startTimetimer1.Starttimer1Tickintifspe
32、ntTime(spentTimeif.ToDouble.Format();=true;=50;newSystem.();(objectEventHandler(timer1_Tick);Environment.TickCountsenderEventArgse)=System.Environment!=0)(upOrDown=1)doublesp=Convert.ToDouble(spentTime)*1000/1024;if(sp<1024)speed.Text=tspBar.Value("0:F1”,sp)+"KB"elsespeed.Text+stri
33、ng.Format("0:F1.TickCount(receivecount.ToString()tspBar.Value.ToStringsp/1024)+"MB/S"startTime;"%下載速度:”()+"%下載速elsedoublesp=Convert.ToDouble(sendCount)/Convert.ToDouble(spentTime)*1000/1024;上傳速度:”"%上傳速if(sp<1024)speed.Text=tspBar.Value.ToString()+"%+string.Forma
34、t("0:F1”,sp)+"KB"elsespeed.Text=tspBar.Value.ToString()+度:"+string.Format("0:F1",sp/1024)+"MB/S"privatevoidDownload()trystringins="name="+fileName;bytedata=Encoding.BigEndianUnicode.GetBytes(ins);wordSocket.Send(data,data.Length,SocketFlags.None);/發(fā)送
35、下載請(qǐng)求GetFileName(fileName);DirectoryFileStreamFileAccess.Write);wordSocketstringreFileName=savePath+""+FileMode.CreateNone);/接收文件CreateDirectory(savePath);fs=newFileStream(reFileName.Receive(buffer,8,SocketFlags大小longfilesize=BitConverter.ToInt64(buffer,0);while(receivecount<filesize)/接收
36、文件intreadcount=wordSocket.Receive(buffer,bufferSizeSocketFlags.None);fs.Write(buffer,0,readcount);receivecount+=readcount;(receivecounttspBar.Value=Convert.ToInt32(Convert.ToDoubleConvert.ToDouble(filesize)*100);tspBar.Value=100;timer1_Tick(newobject(),newEventArgs();fs.Close();timer1.Stop();StaticV
37、alue.isBusy=false;catch(MessageBox.Show("連接斷開(kāi).");timeri.Stop();if(wordSocket.Connected=true)(wordSocket.Shutdown(Socketshutdown.Both);wordSocket.Close();timeri.Stop();StaticValue.isBusy=false;)privatevoidUpload()(try(stringshortFileName=fileName.Substring(fileName.LastIndexOf('')+1
38、,fileName.Length-fileName.LastIndexOf('')-1);stringserverFileName=StaticValue.curServerPath+""+shortFileName;/指定上傳到服務(wù)器的哪個(gè)路徑stringins="upld="+serverFileName;bytebyins=Encoding.BigEndianUnicode.GetBytes(ins);wordSocket.Send(byins,byins.Length,SocketFlags.None);/發(fā)送上傳請(qǐng)求及完整文件名
39、FileStreamfs=newFileStream(fileName,FileMode.Open,FileAccess.Read);longsize=fs.Length;bytebysize=BitConverter.GetBytes(size);wordSocket.Send(bysize,8,SocketFlags.None);/發(fā)送上傳文件大小BinaryReaderbr=newBinaryReader(fs);while(sendCount<size)/發(fā)送文件(intreadcount=br.Read(buffer,0,bufferSize);sendCount+=readc
40、ount;wordSocket.Send(buffer,readcount,SocketFlags.None);tspBar.Value=Convert.ToInt32(Convert.ToDouble(sendCount)/Convert.ToDouble(size)*100);tspBar.Value=100;timer1_Tick(newobject(),newEventArgs();fs.Close();timer1.Stop();StaticValue.isBusy=false;catch(Exceptione)MessageBox.Show("連接斷開(kāi).");w
41、ordSocket.Shutdown(SocketShutdown.Both);wordSocket.Close();timer1.Stop();StaticValue.isBusy=false;publicstringGetFileName(stringfileName)returnfileName.Substring(fileName.LastIndexOf('')+1,fileName.Length-fileName.LastIndexOf('')-1);publicstringGetFileType(stringfileName)returnfileNa
42、me.Substring(fileName.LastIndexOf('.'),fileName.Length-fileName.LastIndexOf('.');/下面給出各按鈕點(diǎn)擊事件/<summary>/連接服務(wù)器按鈕點(diǎn)擊事件/</summary>/<paramname="sender"></param>/<paramname="e"></param>privatevoidbtn_Connect_Click(objectsender,EventAr
43、gse)hostIPAddress=IPAddress.Parse(ttxb_IPAdd.Text);intport=Convert.ToInt32(ttxb_port.Text);Server=newIPEndPoint(hostIPAddress,port);sock=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);trysock.Connect(Server);/連接服務(wù)器toolStripStatusLabel1.Text="與遠(yuǎn)程主機(jī)"+ttxb_IPAdd.Text
44、+""+ttxb_port.ToString()+"連接成功"器根目錄圖標(biāo)RefreshListView(GetDtListArray("boot",false);/獲取服務(wù)connectDonetsBtnConnecttsBtnDisConnectcatchtrue;.Enabled.Enabledfalse;trueMessageBox.Show("連接失敗.");if(sock.Connectedtrue)sock.Shutdown(SocketShutdownsock.Close();.Both);/sum
45、mary下載文件點(diǎn)擊事件</summary><paramname="sender"></param><paramname="e"></param>privatevoidDownLoadprivatevoidifbtnGetFileClick(listViewl(objectsender,EventArgse);/調(diào)用自定義方法下載文件DownLoad(ListView(listViewllistViewl返回上層”stringsizeif(size!=listViewlSelectedIndic
46、es.SelectedIndices=listView1.Count0!=0).SelectedItems"")/如果選定的是文件0&&/0.有選定項(xiàng)且選定的不是SubItems1.Text;listView2.ItemsSelectedItemslistView2.ItemsAdd(listView10.SubItemslistView2.Items.SubItems.Add(size);listView2.ItemslistView2.ImageIndex.SelectedItemsintindex0.Text);.Count-1/將文件大小加入list
47、View.Items.Count-1=ICOSearcher.GetIcoIndex(listViewl0.SubItems0.Text);/獲取該文件的listView1.SelectedIndices0-1;stringFileName=fullNameListindex;downloaditemnewfile=newdownloaditem(FileName,StaticValue.curSavePath);downQueue.Enqueue(newfile);)else/如果是文件夾(stringdownPath=StaticValue.curServerPath+"&quo
48、t;+listViewl.Selecteditems0.SubItems0.Text;stringlistArray=GetDtListArray(downPath,true);Queue<downloaditem>tempQueue=GetDownFileQueue(listArray);while(tempQueue.Count>0)(downQueue.Enqueue(tempQueue.Dequeue();)/<summary>/設(shè)置保存位置的按鈕點(diǎn)擊事件/</summary>/<paramname="sender"&
49、gt;</param>/<paramname="e"></param>privatevoidtsBtn_savePath_Click(objectsender,EventArgse)(if(folderBrowserDialogl.ShowDialog()=DialogResult.OK)(StaticValue.curSavePath=folderBrowserDialogl.SelectedPath;)/<summary>/點(diǎn)擊斷開(kāi)連接的按鈕事件,斷開(kāi)連接,并清空l(shuí)istView等/</summary>/<
50、;paramname="sender"></param>/<paramname="e"></param>privatevoidtsBtn_DisConnect_Click(objectsender,EventArgse)/(try(stringins="quit"bytebyins=Encoding.BigEndianUnicode.GetBytes(ins);sock.Send(byins,byins.Length,SocketFlags.None);sock.Shutdown(Socketshutdown.Both);sock.Close();tsBtn_Connect.Enabled=true;tsBtn_DisConnect.Enabled
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 現(xiàn)代商務(wù)場(chǎng)合下的著裝與舉止規(guī)范
- 居然之家國(guó)慶節(jié)活動(dòng)方案
- 現(xiàn)代農(nóng)業(yè)旅游產(chǎn)業(yè)鏈構(gòu)建與農(nóng)業(yè)可持續(xù)發(fā)展
- 未來(lái)生態(tài)社區(qū)的規(guī)劃與水環(huán)境關(guān)系探討
- 災(zāi)害預(yù)防教育在學(xué)校的推廣與應(yīng)用
- 匯報(bào)邏輯清晰度職場(chǎng)的制勝法寶
- 6 飛向藍(lán)天的恐龍說(shuō)課稿-2023-2024學(xué)年四年級(jí)下冊(cè)語(yǔ)文統(tǒng)編版
- 2023九年級(jí)物理上冊(cè) 第四章 探究電流4.3 導(dǎo)體對(duì)電流阻礙作用說(shuō)課稿 (新版)教科版
- 2 送元二使安西(說(shuō)課稿)- 2024-2025學(xué)年部編版語(yǔ)文六年級(jí)上冊(cè)
- 2024-2025學(xué)年高中數(shù)學(xué) 第一章 集合與常用邏輯用語(yǔ) 1.4.2 充要條件說(shuō)課稿 新人教A版必修第一冊(cè)001
- 2024年公安機(jī)關(guān)理論考試題庫(kù)附答案【考試直接用】
- 課題申報(bào)參考:共同富裕進(jìn)程中基本生活保障的內(nèi)涵及標(biāo)準(zhǔn)研究
- 2025年浙江嘉興桐鄉(xiāng)市水務(wù)集團(tuán)限公司招聘10人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 食品企業(yè)如何做好蟲(chóng)鼠害防控集
- 2025中國(guó)聯(lián)通北京市分公司春季校園招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- 康復(fù)醫(yī)學(xué)科患者隱私保護(hù)制度
- 環(huán)保工程信息化施工方案
- 狂犬病暴露后預(yù)防處置
- 紅色中國(guó)風(fēng)2025蛇年介紹
- 2024年安徽省高考地理試卷真題(含答案逐題解析)
- 高中學(xué)校開(kāi)學(xué)典禮方案
評(píng)論
0/150
提交評(píng)論