資源簡介
完整代碼,重新編譯,界面非常人性化,而且注釋很清晰。能夠?qū)崿F(xiàn)登陸、匿名登陸、上傳、下載、創(chuàng)建、刪除等功能,對初學(xué)者有很好的參考價值。

代碼片段和文件信息
using?System;
using?System.IO;
//?添加命令空間
using?System.Net;
using?System.Text;
using?System.Windows.Forms;
namespace?FTP
{
????public?partial?class?Form1?:?Form
????{
????????private?const?int?ftpport?=?21;
????????private?string?ftpUristring?=?null;
????????private?NetworkCredential?networkCredential;
????????private?string?currentDir?=?“/“;
????????public?Form1()
????????{
????????????InitializeComponent();
????????????IPAddress[]?ips?=?Dns.GetHostAddresses(““);
????????????ServerIp.Text?=?ips[1].ToString();
????????????ServerIp.SelectAll();
????????????logout.Enabled?=?false;
????????????FtpResources.Enabled?=?false;
????????????FtpState.Enabled?=?false;
????????????Upload.Enabled?=?false;
????????????download.Enabled?=?false;
????????????Delete.Enabled?=?false;
????????}
????????#region?鍵盤按下事件
????????private?void?tbxServerIp_KeyPress(object?sender?KeyPressEventArgs?e)
????????{
????????????//?輸入用戶名回車后,焦點直接轉(zhuǎn)到密碼文本框
????????????if?(e.KeyChar?==?(char)13)
????????????{
????????????????Username.Focus();
????????????}
????????}
????????private?void?tbxUsername_KeyPress(object?sender?KeyPressEventArgs?e)
????????{
????????????//?輸入用戶名回車后,焦點直接轉(zhuǎn)到密碼文本框
????????????if?(e.KeyChar?==?(char)13)
????????????{
????????????????Password.Focus();
????????????}
????????}
????????private?void?tbxPassword_KeyPress(object?sender?KeyPressEventArgs?e)
????????{
????????????//?輸入密碼回車后直接可以登錄
????????????if?(e.KeyChar?==?(char)13)
????????????{
????????????????login.Focus();
????????????}
????????}
????????#endregion
????????//?匿名復(fù)選框Click事件
????????private?void?Anonymous_Click(object?sender?EventArgs?e)
????????{
????????????//?實名方式登錄
????????????//?此時需要輸入用戶名和密碼
????????????if?(Anonymous.Checked?==?false)
????????????{
????????????????Username.Enabled?=?true;
????????????????Username.Text?=?“user1“;
????????????????Password.Enabled?=?true;
????????????????Password.Text?=?““;
????????????????Username.Focus();
????????????}
????????????//?匿名方式
????????????else
????????????{
????????????????Username.Text?=?“anonymous“;
????????????????Username.Enabled?=?false;
????????????????Password.Text?=?““;
????????????????Password.Enabled?=?false;
????????????}
????????}
????????#region?與服務(wù)器的交互
????????
????????//?創(chuàng)建FTP連接
????????private?FtpWebRequest?CreateFtpWebRequest(string?uri?string?requestMethod)
????????{
????????????FtpWebRequest?request?=?(FtpWebRequest)FtpWebRequest.Create(uri);
????????????request.Credentials?=?networkCredential;
????????????request.KeepAlive?=?true;
????????????request.UseBinary?=?true;
????????????request.Method?=?requestMethod;
????????????return?request;
????????}
????????//?獲取服務(wù)器返回的響應(yīng)體
????????private?FtpWebResponse?GetFtpResponse(FtpWebRequest?request)
????????{
????????????FtpWebResponse?response?=?null;
????????????try
????????????{
????????????????response?=?(FtpWebResponse)request.GetResponse();
????????????????FtpState.Items.Add(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????47616??2016-04-07?15:26??FTP\.vs\FTP\v14\.suo
?????文件??????20480??2015-06-10?15:56??FTP\FTP\bin\Debug\FTP.exe
?????文件??????36352??2015-06-10?15:56??FTP\FTP\bin\Debug\FTP.pdb
?????文件??????23168??2015-06-10?20:37??FTP\FTP\bin\Debug\FTP.vshost.exe
?????文件????????490??2013-06-18?20:28??FTP\FTP\bin\Debug\FTP.vshost.exe.manifest
?????文件??????19968??2015-06-10?15:21??FTP\FTP\bin\Debug\FTPUpDownloader.exe
?????文件??????42496??2015-06-10?15:21??FTP\FTP\bin\Debug\FTPUpDownloader.pdb
?????文件????????490??2013-06-18?20:28??FTP\FTP\bin\Debug\FTPUpDownloader.vshost.exe.manifest
?????文件??????22528??2016-04-07?10:22??FTP\FTP\bin\Release\FTP.exe
?????文件??????30208??2016-04-07?10:22??FTP\FTP\bin\Release\FTP.pdb
?????文件??????22696??2016-04-07?15:26??FTP\FTP\bin\Release\FTP.vshost.exe
?????文件????????490??2015-10-30?15:19??FTP\FTP\bin\Release\FTP.vshost.exe.manifest
?????文件??????20078??2015-06-13?12:45??FTP\FTP\Form1.cs
?????文件??????12088??2015-06-13?12:45??FTP\FTP\Form1.Designer.cs
?????文件??????11015??2015-06-13?09:57??FTP\FTP\Form1.resx
?????文件???????5345??2015-06-10?15:32??FTP\FTP\FTP.csproj
?????文件????????478??2015-06-10?15:32??FTP\FTP\FTP.csproj.user
?????文件???????3262??2015-06-13?09:55??FTP\FTP\FTP.ico
?????文件???????5426??2015-06-10?15:55??FTP\FTP\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6948??2015-06-10?15:33??FTP\FTP\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????398??2015-06-10?20:37??FTP\FTP\obj\x86\Debug\FTP.csproj.FileListAbsolute.txt
?????文件????????977??2015-06-10?15:52??FTP\FTP\obj\x86\Debug\FTP.csproj.GenerateResource.Cache
?????文件???????9180??2015-06-10?15:33??FTP\FTP\obj\x86\Debug\FTP.csprojResolveAssemblyReference.cache
?????文件??????20480??2015-06-10?15:56??FTP\FTP\obj\x86\Debug\FTP.exe
?????文件??????36352??2015-06-10?15:56??FTP\FTP\obj\x86\Debug\FTP.pdb
?????文件????????180??2015-06-10?15:33??FTP\FTP\obj\x86\Debug\FTP.Properties.Resources.resources
?????文件???????1627??2015-06-10?15:25??FTP\FTP\obj\x86\Debug\FTPUpDownloader.csproj.FileListAbsolute.txt
?????文件????????904??2015-06-10?15:21??FTP\FTP\obj\x86\Debug\FTPUpDownloader.csproj.GenerateResource.Cache
?????文件???????9180??2015-06-10?15:21??FTP\FTP\obj\x86\Debug\FTPUpDownloader.csprojResolveAssemblyReference.cache
?????文件??????19968??2015-06-10?15:21??FTP\FTP\obj\x86\Debug\FTPUpDownloader.exe
............此處省略41個文件信息
評論
共有 條評論