• 将FTP上文件下载到本地


         /// <summary>
            /// 获取FTP文档
            /// </summary>
            /// <returns>路径</returns>
            public static string DisplayFileFromServer(Uri serverUri, out string errorMsg,string username= "test", string userpwd= "test")
            {
                errorMsg = string.Empty;
                if (serverUri.Scheme != Uri.UriSchemeFtp)
                {
                    errorMsg = "路径非FTP";
                    return null;
                }
                WebClient request = new WebClient();
                request.Credentials = new NetworkCredential(username,userpwd);
                
                try
                {
                    byte[] newFileData = request.DownloadData(serverUri.ToString());
    
                    string Path = @"D:GeneFile" + serverUri.Segments.Last().Split('.')[0] + "\";
                    if (!System.IO.Directory.Exists(Path))
                        System.IO.Directory.CreateDirectory(Path);
    
                    //string newFileName = serverUri.LocalPath.Remove(0,serverUri.LocalPath.LastIndexOf('.')).Insert(0, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"));
                    string newFileName = serverUri.Segments.Last();
                    string PathUrl = Path + newFileName;
                    if (File.Exists(PathUrl))
                        File.Delete(PathUrl);
    
                    File.WriteAllBytes(PathUrl, newFileData);
                    
                    return PathUrl;
                }
                catch (WebException ex)
                {
                    errorMsg = ex.Message;
                    Log.WriteLog(ex);
                }
                return null;
            }
  • 相关阅读:
    敏感信息脱敏实现
    SpringBoot集成Swagger2
    CSS三大特性
    background
    background-attachment
    background-position
    background-repeat
    background-image
    background-color
    CSS元素显示模式
  • 原文地址:https://www.cnblogs.com/yy15611/p/13370991.html
Copyright © 2020-2023  润新知