zoukankan      html  css  js  c++  java
  • 上传文件到服务器

        public string SaveServerFile(string tempfilename, string filepath, string filename, bool isLocal = false)
            {
                #region MyRegion
                bool UseWeb = bool.Parse(ConfigurationManager.AppSettings["WebFileService"]);
     
                //判断是否启用文件服务器
                if (UseWeb && !isLocal)
                {
                    //存储临时文件
                    string uri = GetBaseServerSaveFilePath() + filepath;
                    string urishow = GetBaseServerFilePath() + filepath;
     
                    try
                    {
                        if (uri.StartsWith("http"))
                        {
                            WebClient webClient = new WebClient();
                            webClient.UploadFile(uri, "POST", tempfilename);
                            File.Delete(tempfilename);//删除临时上传文件
                            return urishow;
                        }
                        else
                        {
                            string userName = ConfigurationManager.AppSettings["ftpuser"];
                            string userPwd = ConfigurationManager.AppSettings["ftppwd"];
     
                            FtpHelper webClient = new FtpHelper(uri, userName, userPwd);
                            webClient.Upload(tempfilename);
                            //File.Delete(tempfilename);//删除临时上传文件
                            return urishow;
                        }
                    }
                    catch (Exception exception)
                    {
                        return exception.Message;
                    }
                }
                else
                {
                    if (!filepath.EndsWith("/"))
                    {
                        // filepath += "/";
                    }
                    string savefile = GetBaseServerFilePath(isLocal);
                    if (!savefile.EndsWith("/") || (filepath.IsNotNullOrEmpty() && !filepath.StartsWith("/")))
                
                        savefile += filepath;
                    if (!Directory.Exists(savefile))
                        Directory.CreateDirectory(savefile);
                    savefile += filename;
                    filepath += savefile;
                 
                }
     
                #endregion
     
                return filepath;
     
     
            }
  • 相关阅读:
    闲着写了一个查看股票的程序
    Oracle10g正则表达式
    跨语言平台的RSA加密、解密、签名、验证算法的实现
    Base64转换:AQAB=65537,你知道为什么吗?
    无题
    07年了,新的一年又开始了
    简单生活
    近期关注
    闲话
    各大网站的WEB服务器分析
  • 原文地址:https://www.cnblogs.com/nayilvyangguang/p/9981580.html
Copyright © 2011-2022 走看看