• 大小: 0.07M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: 其他
  • 标签: 其他  

资源简介

MyWatch.zip

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace MyWatch
{
    static public class FtpHelper
    {
        //基本设置
        static private string path = @“ftp://“ + ConfigurationManager.AppSettings[“ServerIp“] + “/“; //目标路径
        static private string ftpip = ConfigurationManager.AppSettings[“ServerIp“]; //ftp IP地址
        static private string username = ConfigurationManager.AppSettings[“Username“];//ftp用户名
        static private string password = ConfigurationManager.AppSettings[“Password“];//ftp密码

        //获取ftp上面的文件和文件夹
        public static string[] GetFileList(string dir)
        {
            string[] downloadFiles;
            StringBuilder result = new StringBuilder();
            FtpWebRequest request;
            try
            {
                request = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
                request.UseBinary = true;
                request.Credentials = new NetworkCredential(username password);//设置用户名和密码
                request.Method = WebRequestMethods.Ftp.ListDirectory;
                request.UseBinary = true;

                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string line = reader.ReadLine();
                while (line != null)
                {
                    result.Append(line);
                    result.Append(“\n“);
                    Console.WriteLine(line);
                    line = reader.ReadLine();
                }
                // to remove the trailing ‘\n‘
                result.Remove(result.ToString().LastIndexOf(‘\n‘) 1);
                reader.Close();
                response.Close();
                return result.ToString().Split(‘\n‘);
            }
            catch (Exception ex)
            {
                Console.WriteLine(“获取ftp上面的文件和文件夹:“ + ex.Message);
                downloadFiles = null;
                return downloadFiles;
            }
        }

        /// 
        /// 获取文件大小
        /// 

        /// ip服务器下的相对路径
        /// 文件大小
        public static int GetFileSize(string file)
        {
            StringBuilder result = new StringBuilder();
            FtpWebRequest request;
            try
            {
                request = (FtpWebRequest)FtpWebRequest.Create(new Uri(path + file));
                request.UseBinary = true;
                request.Credentials = new NetworkCredential(username password);//设置用户名和密码
                request.Method = WebRequestMethods.Ftp.GetFileSize;

                int dataLength = (int)request.GetResponse().ContentLength;

                return dataLength;
            }
            catch (Exception ex)
            {
                Console.Write

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-01-15 11:12  MyWatch\
     目录           0  2015-01-15 10:06  MyWatch\MyWatch\
     文件        1543  2015-01-15 11:13  MyWatch\MyWatch.sln
     文件       36352  2015-01-15 12:29  MyWatch\MyWatch.suo
     文件         673  2015-01-15 12:21  MyWatch\MyWatch\App.config
     目录           0  2015-01-14 15:08  MyWatch\MyWatch\bin\
     目录           0  2015-01-15 11:38  MyWatch\MyWatch\bin\Debug\
     文件       18432  2015-01-15 11:37  MyWatch\MyWatch\bin\Debug\MyWatch.exe
     文件         662  2015-01-15 11:38  MyWatch\MyWatch\bin\Debug\MyWatch.exe.Config
     文件       40448  2015-01-15 11:37  MyWatch\MyWatch\bin\Debug\MyWatch.pdb
     文件       11600  2015-01-15 11:38  MyWatch\MyWatch\bin\Debug\MyWatch.vshost.exe
     文件         664  2015-01-15 11:35  MyWatch\MyWatch\bin\Debug\MyWatch.vshost.exe.config
     目录           0  2015-01-14 15:08  MyWatch\MyWatch\bin\Release\
     文件       11777  2015-01-15 10:39  MyWatch\MyWatch\FtpHelper.cs
     文件        7730  2015-01-15 12:27  MyWatch\MyWatch\MyForm.cs
     文件        9008  2015-01-15 11:18  MyWatch\MyWatch\MyForm.Designer.cs
     文件        5817  2015-01-15 11:18  MyWatch\MyWatch\MyForm.resx
     文件        3953  2015-01-15 10:07  MyWatch\MyWatch\MyWatch.csproj
     目录           0  2015-01-14 14:51  MyWatch\MyWatch\obj\
     目录           0  2015-01-14 14:51  MyWatch\MyWatch\obj\x86\
     目录           0  2015-01-15 11:37  MyWatch\MyWatch\obj\x86\Debug\
     文件        5359  2015-01-14 15:34  MyWatch\MyWatch\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6655  2015-01-15 11:37  MyWatch\MyWatch\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         597  2015-01-15 11:38  MyWatch\MyWatch\obj\x86\Debug\MyWatch.csproj.FileListAbsolute.txt
     文件         976  2015-01-15 11:28  MyWatch\MyWatch\obj\x86\Debug\MyWatch.csproj.GenerateResource.Cache
     文件       18432  2015-01-15 11:37  MyWatch\MyWatch\obj\x86\Debug\MyWatch.exe
     文件         180  2015-01-15 11:28  MyWatch\MyWatch\obj\x86\Debug\MyWatch.MyForm.resources
     文件       40448  2015-01-15 11:37  MyWatch\MyWatch\obj\x86\Debug\MyWatch.pdb
     文件         180  2015-01-15 10:20  MyWatch\MyWatch\obj\x86\Debug\MyWatch.Properties.Resources.resources
     目录           0  2015-01-15 10:08  MyWatch\MyWatch\obj\x86\Debug\TempPE\
     文件         489  2015-01-14 14:56  MyWatch\MyWatch\Program.cs
............此处省略6个文件信息

评论

共有 条评论