91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 22KB
    文件類型: .cs
    金幣: 1
    下載: 0 次
    發布日期: 2021-06-06
  • 語言: C#
  • 標簽: C#??FTP??上傳??下載??

資源簡介

首先得搭建一個FTP服務器,然后若想對服務器或本地文件進行FTP上傳、下載、創建目錄、重命名、刪除文件操作,則本文檔中的方法將會對你起到一定的作用。

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.IO;
using?System.Net;
using?System.Diagnostics;
using?System.Text.Regularexpressions;
using?System.Web;

///?
///FtpManager?的摘要說明
///?

public?class?FtpManager
{
????///?
????///?委托,用于標識當前文件下載百分比
????///?

????///?當前文件下載百分比
????//public??delegate?void?DelegateDldPercentage(double?dldPercentage);

????///?
????///?當前下載文件百分比
????///?

????//public?static?event?DelegateDldPercentage?EDldPercentage;

????///?
????///?下載文件
????///?

????///?下載到本地的路徑
????///?要下載
????///?
????///?
????///?
????public?static?bool?DownloadFile(string?saveFilePath?string?filePath?string?ftpServerIP?string?ftpUserName?string?ftpPwd)
????{
????????if?(!Directory.Exists(saveFilePath)?&&?saveFilePath?!=?““?&&?saveFilePath?!=?null)
????????{
????????????Directory.CreateDirectory(saveFilePath);
????????}
????????FileInfo?info?=?new?FileInfo(filePath);
????????using?(FileStream?OutputStream?=?new?FileStream(saveFilePath?+?“/“?+?info.Name?FileMode.Create))????????
????????{
????????????try
????????????{
????????????????FtpWebRequest?ReqFTP?=?(FtpWebRequest)FtpWebRequest.Create(“ftp://“?+?ftpServerIP?+?“/“?+?filePath);
????????????????ReqFTP.Method?=?WebRequestMethods.Ftp.DownloadFile;
????????????????ReqFTP.UseBinary?=?true;
????????????????ReqFTP.Credentials?=?new?NetworkCredential(ftpUserName?ftpPwd);

????????????????using?(FtpWebResponse?response?=?(FtpWebResponse)ReqFTP.GetResponse())
????????????????{
????????????????????////當前已下載文件百分比
????????????????????//double?currentPercentage?=?0;
????????????????????////當前已下載文件大小
????????????????????//long?currentDldBytes?=?0;
????????????????????//文件大小
????????????????????string?FtpFilePath?=?“ftp://“?+?ftpServerIP?+?“/“?+?filePath;
????????????????????long?fileLength?=?GetFileLength(FtpFilePath?ftpServerIP?ftpUserName?ftpPwd);
????????????????????using?(Stream?FtpStream?=?response.GetResponseStream())
????????????????????{
????????????????????????//long?Cl?=?response.ContentLength;
????????????????????????int?bufferSize?=?2048;
????????????????????????int?readCount;
????????????????????????byte[]?buffer?=?new?byte[bufferSize];
????????????????????????readCount?=?FtpStream.Read(buffer?0?bufferSize);
????????????????????????while?(readCount?>?0)
????????????????????????{
????????????????????????????//EDldPercentage(currentPercentage);
????????????????????????????OutputStream.Write(buffer?0?readCount);
????????????????????????????readCount?=?FtpStream.Read(buffer?0?bufferSize);
????????????????????????????//currentDldBytes?+=?readCount;
????????????????????????????//currentPercentage?=?(

評論

共有 條評論