zoukankan      html  css  js  c++  java
  • FTP资源下检测URL地址下文件大小

    代码:

    string ftpServerIP;
    string ftpUserID;
    string ftpPassword;
    FtpWebRequest reqFTP;

    //获得文件大小
            public long GetFileSize(string filename)
            {
                long fileSize = 0;
                try
                {
                    FileInfo fileInf = new FileInfo(filename);
                    string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
                    Connect(uri);//连接     
                    reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                    fileSize = response.ContentLength;
                    response.Close();
                }
                catch (Exception ex)
                {
                    if (OnErrorEvent != null) OnErrorEvent(ex.Message);
                }
                return fileSize;
            }

    其中Connect(uri)

        private void Connect(String path)//连接ftp
            {
                // 根据uri创建FtpWebRequest对象
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
    
                // 指定数据传输类型
                 reqFTP.UseBinary = true;
                 //reqFTP.UsePassive = false;
    
                // ftp用户名和密码
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
    
            }
  • 相关阅读:
    Java实现各种排序算法
    Memcached学习笔记
    S.O.L.I.D 原则
    设计模式之Bridge
    UML建模工具比较
    UML建模
    Ps经典实例教程3000例
    ps视频教程全集
    自己做到了吗?
    记事本开发Java代码注意要点
  • 原文地址:https://www.cnblogs.com/wxh19860528/p/2577724.html
Copyright © 2011-2022 走看看