• ftp上传


    public class FtpUtil
        {
            string ftpServerIP;
            string ftpRemotePath;
            string ftpUserID;
            string ftpPassword;
            string ftpURI;
    
            /// <summary>
            /// 连接FTP
            /// </summary>
            /// <param name="FtpServerIP">FTP连接地址</param>
            /// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>
            /// <param name="FtpUserID">用户名</param>
            /// <param name="FtpPassword">密码</param>
            public FtpUtil(string FtpServerIP, string FtpRemotePath, string FtpUserID, string FtpPassword)
            {
                ftpServerIP = FtpServerIP;
                ftpRemotePath = FtpRemotePath;
                ftpUserID = FtpUserID;
                ftpPassword = FtpPassword;
                ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
            }
    
            /// <summary>
            /// 上传
            /// </summary>
            /// <param name="filename"></param>
            public void Upload(string filename)
            {
                FileInfo fileInf = new FileInfo(filename);
                string uri = ftpURI + fileInf.Name;
                FtpWebRequest reqFTP;
    
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                reqFTP.KeepAlive = false;
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
                reqFTP.UseBinary = true;
                reqFTP.UsePassive = false;
                reqFTP.ContentLength = fileInf.Length;
                int buffLength = 2048;
                byte[] buff = new byte[buffLength];
                int contentLen;
                FileStream fs = fileInf.OpenRead();
                try
                {
                    Stream strm = reqFTP.GetRequestStream();
                    contentLen = fs.Read(buff, 0, buffLength);
                    while (contentLen != 0)
                    {
                        strm.Write(buff, 0, contentLen);
                        contentLen = fs.Read(buff, 0, buffLength);
                    }
                    strm.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    throw new Exception("Ftphelper Upload Error --> " + ex.Message);
                }
            }
    
        }
  • 相关阅读:
    Codeforces Global Round 17
    [UER #6] 逃跑
    [模板] 一般图最大匹配
    Codeforces Global Round 18
    Flash/Flex学习笔记(50):3D线条与填充
    Flash/Flex学习笔记(47):反向运动学(上)
    Flash/Flex学习笔记(46):正向运动学
    Flash/Flex学习笔记(49):3D基础
    Flash/Flex学习笔记(51):3维旋转与透视变换(PerspectiveProjection)
    Flash/Flex学习笔记(54):迷你滚动条ScrollBar
  • 原文地址:https://www.cnblogs.com/tangchun/p/9967525.html
Copyright © 2020-2023  润新知