当前位置: 首页 > news >正文

C# ftp帮助类 项目实战优化版

        上位机开发中有时要与客户的文件服务器进行数据交互。如Mapping文件下载。结果文件上传等。我在项目中就常用到。现在把项目实战代码进行分享一下。

        功能列表:连接服务器,下载文件,上传文件,删除服务器文件,获取当前目录下明细(包含文件和文件夹)  ,获取FTP文件列表(包括文件夹),获取当前目录下文件列表(不包括文件夹)  ,创建文件夹,获取指定文件大小  ,更改文件名,移动文件  ,删除ftpURI目录下指定的文件夹

调用

        1.初始化连接

        CommonData.FtpServer_MappingFile = new FTPHelper(ftpIPAddress, ftpUser, ftpPw);

        2.下载

        //url 服务器下载地址

        //savefilePath 保存文件目录

        //fileName 文件名,只是文件名

        CommonData.FtpServer_MappingFile.DownloadByUrl(url, savefilePath, fileName, true);

        3.上传

        //currentDirectory 本地文件完整路径包括文件名

        //ftpUploadFileName FTP服务器完整上传路径包括文件名

        CommonData.FtpServer_MappingFile.Upload(currentDirectory, ftpUploadFileName);

代码

/// <summary>/// ftp帮助类/// </summary>public class FTPHelper{#region 字段string ftpURI;string ftpUserID;string ftpServerIP;string ftpPassword;string ftpRemotePath;/// <summary>/// 下载URL/// </summary>public string DownloadUrl { get; set; }#endregionpublic string GetFtpURI(){return ftpURI;}//public FTPHelper() { }/// <summary>  /// 连接FTP服务器/// </summary>  /// <param name="FtpServerIP">FTP连接地址</param>  /// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>  /// <param name="FtpUserID">用户名</param>  /// <param name="FtpPassword">密码</param>  public FTPHelper(string FtpServerIP, string FtpRemotePath, string FtpUserID, string FtpPassword, bool isFile = false){ftpServerIP = FtpServerIP;ftpRemotePath = FtpRemotePath;ftpUserID = FtpUserID;ftpPassword = FtpPassword;//ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";if (isFile){ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath.Replace("\\", "/");}}/// <summary>  /// 连接FTP服务器/// </summary>  /// <param name="FtpServerIP">FTP连接地址</param>  /// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>  /// <param name="FtpUserID">用户名</param>  /// <param name="FtpPassword">密码</param>  public FTPHelper(string FtpServerIP, string FtpUserID, string FtpPassword){ftpServerIP = FtpServerIP;//ftpRemotePath = FtpRemotePath;ftpUserID = FtpUserID;ftpPassword = FtpPassword;//ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";ftpURI = "ftp://" + ftpServerIP;//+ "/" + ftpRemotePath + "/";//if (isFile)//{//    ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath.Replace("\\", "/");//}}/// <summary>  /// 上传  filename是本地图片的地址/// </summary>   public void Upload(string filename){FileInfo fileInf = new FileInfo(filename);FtpWebRequest reqFTP;reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fileInf.Name));reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.UploadFile;reqFTP.KeepAlive = false;reqFTP.UseBinary = true;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(ex.Message);}}/// <summary>/// 上传/// </summary>/// <param name="fileName">是本地文件全路径</param>/// <param name="ftpUrl"></param>/// <param name="lmDir"></param>/// <returns></returns>public CommonResultModel<string> Upload(string fileName, string ftpUrl){var resultModel = new CommonResultModel<string>();FileInfo fileInf = null;FtpWebRequest reqFTP;Stream strm = null;FileStream fs = null;var uploadUrl = string.Empty;try{//ip/指定目录/lotId/pid.csvuploadUrl = ftpURI + ftpUrl;resultModel.Data = uploadUrl;//var ftpDir = uploadUrl.Replace(lmDir, string.Empty);var ftpDirList = ftpUrl.Split('/').ToList();ftpDirList = ftpDirList.FindAll(t => t.Length > 0).FindAll(t => !t.Contains("."));var newDir = ftpURI;//判断文件夹是否存在//resultModel.Msg = "Upload 判断文件夹是否存在 ";//CommonDefine.SaveWorkLogs(resultModel.Msg);foreach (var item in ftpDirList){//newDir += "/" + item;var isExists = FolderExists(newDir, item);newDir += "/" + item;//resultModel.Msg += "newDir:" + newDir + ",isExists:" + isExists + ",";//CommonDefine.SaveWorkLogs(resultModel.Msg);if (!isExists){var makeDirResultModel = MakeDir(newDir);//CommonDefine.SaveWorkLogs(resultModel.Msg//    + ", MakeDir: IsSucceed=" + makeDirResultModel.IsSucceed + ",msg:" + makeDirResultModel.Msg);//if (!makeDirResultModel.IsSucceed)//{//    throw new Exception(makeDirResultModel.Msg);//}}}fileInf = new FileInfo(fileName);reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uploadUrl));reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.UploadFile;reqFTP.KeepAlive = false;reqFTP.UseBinary = true;reqFTP.ContentLength = fileInf.Length;int buffLength = 2048;byte[] buff = new byte[buffLength];int contentLen;fs = fileInf.OpenRead();strm = reqFTP.GetRequestStream();contentLen = fs.Read(buff, 0, buffLength);while (contentLen != 0){strm.Write(buff, 0, contentLen);contentLen = fs.Read(buff, 0, buffLength);}}catch (Exception ex){//throw new Exception("uploadUrl:" + uploadUrl + ",Message:" + ex.Message);resultModel.Msg = "异常:" + ex.Message;}finally{if (strm != null){strm.Close();}if (fs != null){fs.Close();}}return resultModel;}/// <summary>  /// 下载  filePath是下载到本机的地址fileName是需要下载的文件的名字/// </summary>   public void Download(string filePath, string fileName, bool isFile = false){try{FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);FtpWebRequest reqFTP;if (isFile){reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));}else{reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fileName));}reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;reqFTP.UseBinary = true;FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream = response.GetResponseStream();long cl = response.ContentLength;int bufferSize = 2048;int readCount;byte[] buffer = new byte[bufferSize];readCount = ftpStream.Read(buffer, 0, bufferSize);while (readCount > 0){outputStream.Write(buffer, 0, readCount);readCount = ftpStream.Read(buffer, 0, bufferSize);}ftpStream.Close();outputStream.Close();response.Close();}catch (Exception ex){throw new Exception(ex.Message);}}/// <summary>/// 下载  filePath是下载到本机的地址fileName是需要下载的文件的名字/// </summary>/// <param name="ftpFilePath">FTP下载文件的路径(/mapping/xxx)</param>/// <param name="savefilePath">本地保存文件路径</param>/// <param name="savefileName">本地保存文件</param>/// <param name="isFile">是否是文件</param>public void DownloadByUrl(string ftpFilePath, string savefilePath, string savefileName, bool isFile = false){try{FileStream outputStream = new FileStream(savefilePath + "\\" + savefileName, FileMode.Create);FtpWebRequest reqFTP;ftpFilePath = ftpFilePath.Replace("\\", "/");if (isFile){//DownloadUrl = ftpURI;DownloadUrl = ftpURI + ftpFilePath;reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(DownloadUrl));}else{//var url = ftpURI + "//" + ftpFilePath.Trim().TrimStart('\\').TrimStart('/');DownloadUrl = ftpURI + ftpFilePath;reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(DownloadUrl));}reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;reqFTP.UseBinary = true;FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream = response.GetResponseStream();long cl = response.ContentLength;int bufferSize = 2048;int readCount;byte[] buffer = new byte[bufferSize];readCount = ftpStream.Read(buffer, 0, bufferSize);while (readCount > 0){outputStream.Write(buffer, 0, readCount);readCount = ftpStream.Read(buffer, 0, bufferSize);}ftpStream.Close();outputStream.Close();response.Close();}catch (Exception ex){throw new Exception("DownloadUrl:" + DownloadUrl + ", errorMsg:" + ex.Message);}}/// <summary>  /// 删除服务器的文件  fileName是需要删除的文件的名字/// </summary>  public void Delete(string fileName){try{FtpWebRequest reqFTP;reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + fileName));reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;reqFTP.KeepAlive = false;string result = String.Empty;FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();long size = response.ContentLength;Stream datastream = response.GetResponseStream();StreamReader sr = new StreamReader(datastream);result = sr.ReadToEnd();sr.Close();datastream.Close();response.Close();}catch (Exception ex){throw new Exception(ex.Message);}}/// <summary>  /// 获取当前目录下明细(包含文件和文件夹)  /// </summary>  public string[] GetFilesDetailList(){try{StringBuilder result = new StringBuilder();FtpWebRequest ftp;ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;WebResponse response = ftp.GetResponse();StreamReader reader = new StreamReader(response.GetResponseStream());string line = reader.ReadLine();line = reader.ReadLine();line = reader.ReadLine();while (line != null){result.Append(line);result.Append("\n");line = reader.ReadLine();}result.Remove(result.ToString().LastIndexOf("\n"), 1);reader.Close();response.Close();return result.ToString().Split('\n');}catch (Exception ex){throw new Exception(ex.Message);}}/// <summary>  /// 获取FTP文件列表(包括文件夹)/// </summary>   private List<string> GetAllList(string url){List<string> list = new List<string>();FtpWebRequest req = (FtpWebRequest)WebRequest.Create(new Uri(url));req.Credentials = new NetworkCredential(ftpUserID, ftpPassword);req.Method = WebRequestMethods.Ftp.ListDirectory;req.UseBinary = true;req.UsePassive = true;try{using (FtpWebResponse res = (FtpWebResponse)req.GetResponse()){using (StreamReader sr = new StreamReader(res.GetResponseStream())){string s;while ((s = sr.ReadLine()) != null){list.Add(s);}}}}catch (Exception ex){throw (ex);}return list;}/// <summary>  /// 获取当前目录下文件列表(不包括文件夹)  /// </summary>  public List<string> GetFileList(string url){var fileNameList = new List<string>();//StringBuilder result = new StringBuilder();FtpWebRequest reqFTP;try{reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));reqFTP.UseBinary = true;reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;WebResponse response = reqFTP.GetResponse();StreamReader reader = new StreamReader(response.GetResponseStream());string line = reader.ReadLine();while (line != null){//rwxrwxr--    1 1001     1001         4520 Oct 31  2023 AD2300225P1.xmlCommonDefine.SaveWorkLogs("GetFileList() " + line);//if (line.IndexOf("<DIR>") == -1)//{//    var fileName = Regex.Match(line, @"[\S]+ [\S]+", RegexOptions.IgnoreCase).Value.Split(' ')[1];//    CommonDefine.SaveWorkLogs("GetFileList()1 fileName:" + fileName);//    result.Append(fileName);//    result.Append("\n");//}var textList = line.Split(' ').ToList();var fileName = textList.LastOrDefault();//result.Append(fileName);fileNameList.Add(fileName);line = reader.ReadLine();}//result.Remove(result.ToString().LastIndexOf('\n'), 1);reader.Close();response.Close();}catch (Exception ex){//throw (ex);throw new Exception(ex.Message + ",url:" + url + ",ftpUserID:" + ftpUserID + ",ftpPassword:" + ftpPassword);}//return result.ToString().Split('\n');return fileNameList;}/// <summary>  /// 获取当前目录下文件列表(不包括文件夹)  /// </summary>  public List<string> GetFileListByFilePath(string filePath){var fileList = new List<string>();//var url = ftpURI + "//" + filePath.Trim().TrimStart('\\').TrimStart('/');var url = ftpURI + filePath.Trim();try{//var fileNameArray = GetFileList(ftpURI + "//" + filePath);var fileNameArray = GetFileList(url);if (fileNameArray != null && fileNameArray.Count > 0){fileList = fileNameArray;}}catch (Exception ex){//throw (ex);throw new Exception("url:" + url + ",errormsg:" + ex.Message);}return fileList;}/// <summary>  /// 判断当前目录下指定的文件是否存在  /// </summary>  /// <param name="RemoteFileName">远程文件名</param>  public bool FileExist(string RemoteFileName){var fileList = GetFileList("*.*");foreach (string str in fileList){if (str.Trim() == RemoteFileName.Trim()){return true;}}return false;}/// <summary>  /// 创建文件夹  /// </summary>   public CommonResultModel<string> MakeDir(string ftpDirName){var resultModel = new CommonResultModel<string>();FtpWebRequest reqFTP;FtpWebResponse response = null;try{//resultModel.Msg = "MakeDir 1";reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpDirName));//resultModel.Msg = "MakeDir 2";reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;//创建文件夹reqFTP.UseBinary = true;reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//resultModel.Msg = "MakeDir 3";using (response = (FtpWebResponse)reqFTP.GetResponse()){//resultModel.Msg = "MakeDir 4";Stream ftpStream = response.GetResponseStream();//resultModel.Msg = "MakeDir 5";ftpStream.Close();resultModel.IsSucceed = true;}//response.Close();}catch (Exception ex){//resultModel.Msg = ex.Message;throw ex;}finally{if (response != null){response.Close();}}return resultModel;}/// <summary>/// 判断文件夹是否存在/// </summary>/// <param name="ftpServer"></param>/// <param name="ftpFolder">文件夹</param>/// <param name="ftpUsername"></param>/// <param name="ftpPassword"></param>/// <returns></returns>public bool FolderExists(string ftpFolder, string findFolder){bool folderExists = false;string uploadUrl = string.Empty;try{var fileNameList = CommonData.FtpServer_MappingFile.GetAllList(ftpFolder.Trim());foreach (var item in fileNameList){//this.lbFtpFileNames.Items.Add(item);//CommonDefine.SaveWorkLogs("判断文件夹是否存在 获取FTP所有文件 " + ftpFolder + ":" + item);if (item.Contains(findFolder)){folderExists = true;//CommonDefine.SaveWorkLogs("判断文件夹是否存在 获取FTP所有文件 " + ftpFolder + ":" + item + "," + findFolder + "目录存在");break;}}}catch (WebException ex){var response = (FtpWebResponse)ex.Response;if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable){folderExists = false;}else{// 处理其他异常}}return folderExists;}/// <summary>  /// 获取指定文件大小  /// </summary>  public long GetFileSize(string filename){FtpWebRequest reqFTP;long fileSize = 0;try{reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + filename));reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;reqFTP.UseBinary = true;reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream = response.GetResponseStream();fileSize = response.ContentLength;ftpStream.Close();response.Close();}catch (Exception ex){ }return fileSize;}/// <summary>  /// 更改文件名  /// </summary> public void ReName(string currentFilename, string newFilename){FtpWebRequest reqFTP;try{reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + currentFilename));reqFTP.Method = WebRequestMethods.Ftp.Rename;reqFTP.RenameTo = newFilename;reqFTP.UseBinary = true;reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream = response.GetResponseStream();ftpStream.Close();response.Close();}catch (Exception ex){ }}/// <summary>  /// 移动文件  /// </summary>  public void MovieFile(string currentFilename, string newDirectory){ReName(currentFilename, newDirectory);}/// <summary>  /// 切换当前目录  /// </summary>  /// <param name="IsRoot">true:绝对路径 false:相对路径</param>   public void GotoDirectory(string DirectoryName, bool IsRoot){if (IsRoot){ftpRemotePath = DirectoryName;}else{ftpRemotePath += DirectoryName + "/";}ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";}/// <summary>  /// 删除ftpURI目录下指定的文件夹  /// </summary>   public void DeleteDir(string dirName){FtpWebRequest reqFTP;try{reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI + dirName));reqFTP.Method = WebRequestMethods.Ftp.RemoveDirectory;reqFTP.UseBinary = true;reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();Stream ftpStream = response.GetResponseStream();ftpStream.Close();response.Close();}catch (Exception ex){throw new Exception(ex.Message);}}}

相关文章:

C# ftp帮助类 项目实战优化版

上位机开发中有时要与客户的文件服务器进行数据交互。如Mapping文件下载。结果文件上传等。我在项目中就常用到。现在把项目实战代码进行分享一下。 功能列表&#xff1a;连接服务器&#xff0c;下载文件&#xff0c;上传文件&#xff0c;删除服务器文件&#xff0c;获取当前目…...

栈和队列相关|有效的括号|用队列实现栈|用栈实现队列|设计循环队列(C)

20. 有效的括号 判断左右括号是否匹配&#xff0c;匹配返回true&#xff0c;不匹配返回false 通过栈来实现&#xff0c;类型和顺序&#xff0c;数量都要匹配 控制数量通过size 每个右括号都要找最近的左括号去判断类型匹配不匹配&#xff0c;顺序匹配不匹配 最后来判断数量匹配…...

云原生后端开发教程

云原生后端开发教程 引言 随着云计算的普及&#xff0c;云原生架构逐渐成为现代软件开发的主流。云原生不仅仅是将应用部署到云上&#xff0c;而是一种构建和运行应用的方式&#xff0c;充分利用云计算的弹性和灵活性。本文将深入探讨云原生后端开发的核心概念、工具和实践&a…...

TortoiseSVN小乌龟下载安装(Windows11)

目录 TortoiseSVN 1.14.7工具下载安装 TortoiseSVN 1.14.7 工具 系统&#xff1a;Windows 11 下载 官网&#xff1a;https://tortoisesvn.subversion.org.cn/downloads.html如图选 TortoiseSVN 1.14.7 - 64 位 下载完成 安装 打开 next&#xff0c;next Browse&#xf…...

Android adb命令获取设备id

Android adb命令获取设备id 方式很多&#xff0c;以下均可获得Android device id&#xff1a; adb shell settings get secure android_id adb shell settings get secure android_id adb devices -l adb shell content query --uri content://settings/secure --where "…...

Skywalking教程一

Skywalking教程一 概述Skywalking功能特点&#xff1a; 概述 一个大型分布式系统架构&#xff0c;监控平台是必不可少的&#xff0c;常用的分布式系统监控平台有&#xff1a;SkyWalking和Prometheus。Skywalking是一款比较优秀的分布式系统监控平台&#xff0c;一款分布式系统…...

React中管理state的方式

使用useState 使用useReducer 既然已经有了useState&#xff0c;为什么还需要useReducer呢&#xff1f; 那么useReducer是如何将解决这些问题的呢&#xff1f; reducer是如何更新state的呢&#xff1f; reducer的工作方式非常类似JavaScript中的reduce方法&#xff0c;随着时…...

服务器数据恢复—RAID5阵列中部分成员盘重组RAID5阵列后如何恢复原raid5阵列数据?

服务器数据恢复环境&#xff1a; 一台服务器挂接一台存储&#xff0c;该存储中有一组由5块硬盘组建的RAID5阵列。 服务器故障&#xff1a; 存储raid5阵列中有一块硬盘掉线。由于RAID5的特性&#xff0c;阵列并没有出现问题。工作一段时间后&#xff0c;服务器出现故障&#xff…...

【Linux】文件切割排序 cut sort

文章目录 Linux文件切割命令&#xff1a;cut1. cut命令的基本用法2. cut命令的选项和参数3. cut命令的实际应用案例 Linux文件排序命令&#xff1a;sort1. sort命令的基本用法2. sort命令的选项和参数3. sort命令的实际应用案例 常见问题和解决方案1. cut和sort命令的联合使用2…...

零售EDI:HornBach EDI 项目案例

HornBach 是一家总部位于德国的家居和建筑材料零售商&#xff0c;成立于1968年。它以大型仓储式商店而闻名&#xff0c;提供广泛的产品&#xff0c;包括建筑材料、园艺、家居装饰和工具等。 近期我们帮助HornBach的供应商W公司成功实现了与HornBach的EDI直连&#xff0c;除了满…...

SpringBoot 集成RabbitMQ 实现钉钉日报定时发送功能

文章目录 一、RabbitMq 下载安装二、开发步骤&#xff1a;1.MAVEN 配置2. RabbitMqConfig 配置3. RabbitMqUtil 工具类4. DailyDelaySendConsumer 消费者监听5. 测试延迟发送 一、RabbitMq 下载安装 官网&#xff1a;https://www.rabbitmq.com/docs 二、开发步骤&#xff1a;…...

基于java ssm springboot女士电商平台系统源码+文档设计

基于java ssm springboot女士电商平台系统源码文档设计 &#x1f345; 作者主页 网顺技术团队 &#x1f345; 欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; &#x1f345; 文末获取源码联系方式 &#x1f4dd; &#x1f345; 查看下方微信号获取联系方式 承接各种定制系统…...

Matlab数字信号处理——基于改进小波变换的图像去噪方法(7种去噪算法)

1.基于小波变换的阈值收缩法去噪 该方法利用小波变换分离出信号中的噪声成分&#xff0c;并通过设置合适的阈值对小波系数进行收缩&#xff0c;保留主要信息的同时&#xff0c;去除噪声。 %基于小波变换的阈值收缩法去噪算法 clear clc Iimread(nana.png); X im2double(I); …...

leetcode hot100【LeetCode 70. 爬楼梯】java实现

LeetCode 70. 爬楼梯 题目描述 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢&#xff1f; 注意&#xff1a; 给定 n 是一个正整数。 示例 1&#xff1a; 输入&#xff1a;n 2 输出&#xff1a;2 解释&…...

Java异常2

异常抛出的两种形式&#xff1a; 系统隐式抛出&#xff1b;int n10/0;—隐式抛出一个异常&#xff1b;手动抛出异常&#xff1a;throw new Exception(); import java.util.InputMismatchException; import java.util.Scanner;public class Main {public static void main(Str…...

2024熵密杯初始题2

问题简要&#xff1a; 已知 counter 0x7501E6EA token 0xF4CE927C79B616E8E8F7223828794EEDF9B16591AE572172572D51E135E0D21A 伪造出另一个可以通过验证的counter和token。 给出token生成及验证代码如下&#xff1a; import binascii from gmssl import sm3# 读取HMAC ke…...

echarts属性之title

title 标题组件&#xff0c;包含主标题和副标题。 在 ECharts 2.x 中单个 ECharts 实例最多只能拥有一个标题组件。但是在 ECharts 3 中可以存在任意多个标题组件&#xff0c;这在需要标题进行排版&#xff0c;或者单个实例中的多个图表都需要标题时会比较有用。 例如下面不…...

VUE errolog, vue 错误集

I) installation As to command “npm install” on cmd or powershell, we must execute it under the program folder...

驱动开发系列13 - Linux tasklet用法介绍

一:概述 Tasklet 是 Linux 内核中的一种轻量级任务调度机制,通常用于在中断上下文中执行短小的任务。它们在软中断处理过程中被调用,允许将较长的处理工作延后到一个较低优先级的上下文中,以减少中断处理的延迟。Tasklet 的使用可以帮助开发者更好地管理系统资源,提高性能…...

redis实现分布式锁,go实现完整code

Redis分布式锁 Redis 分布式锁是一种使用 Redis 数据库实现分布式锁的方式&#xff0c;可以保证在分布式环境中同一时间只有一个实例可以访问共享资源。 实现机制 以下是实现其加锁步骤&#xff1a; 获取锁 在 Redis 中&#xff0c;一个相同的key代表一把锁。是否拥有这把锁&…...

eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)

说明&#xff1a; 想象一下&#xff0c;你正在用eNSP搭建一个虚拟的网络世界&#xff0c;里面有虚拟的路由器、交换机、电脑&#xff08;PC&#xff09;等等。这些设备都在你的电脑里面“运行”&#xff0c;它们之间可以互相通信&#xff0c;就像一个封闭的小王国。 但是&#…...

设计模式和设计原则回顾

设计模式和设计原则回顾 23种设计模式是设计原则的完美体现,设计原则设计原则是设计模式的理论基石, 设计模式 在经典的设计模式分类中(如《设计模式:可复用面向对象软件的基础》一书中),总共有23种设计模式,分为三大类: 一、创建型模式(5种) 1. 单例模式(Sing…...

mongodb源码分析session执行handleRequest命令find过程

mongo/transport/service_state_machine.cpp已经分析startSession创建ASIOSession过程&#xff0c;并且验证connection是否超过限制ASIOSession和connection是循环接受客户端命令&#xff0c;把数据流转换成Message&#xff0c;状态转变流程是&#xff1a;State::Created 》 St…...

LeetCode - 394. 字符串解码

题目 394. 字符串解码 - 力扣&#xff08;LeetCode&#xff09; 思路 使用两个栈&#xff1a;一个存储重复次数&#xff0c;一个存储字符串 遍历输入字符串&#xff1a; 数字处理&#xff1a;遇到数字时&#xff0c;累积计算重复次数左括号处理&#xff1a;保存当前状态&a…...

python爬虫:Newspaper3k 的详细使用(好用的新闻网站文章抓取和解析的Python库)

更多内容请见: 爬虫和逆向教程-专栏介绍和目录 文章目录 一、Newspaper3k 概述1.1 Newspaper3k 介绍1.2 主要功能1.3 典型应用场景1.4 安装二、基本用法2.2 提取单篇文章的内容2.2 处理多篇文档三、高级选项3.1 自定义配置3.2 分析文章情感四、实战案例4.1 构建新闻摘要聚合器…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

Mysql中select查询语句的执行过程

目录 1、介绍 1.1、组件介绍 1.2、Sql执行顺序 2、执行流程 2.1. 连接与认证 2.2. 查询缓存 2.3. 语法解析&#xff08;Parser&#xff09; 2.4、执行sql 1. 预处理&#xff08;Preprocessor&#xff09; 2. 查询优化器&#xff08;Optimizer&#xff09; 3. 执行器…...

算法:模拟

1.替换所有的问号 1576. 替换所有的问号 - 力扣&#xff08;LeetCode&#xff09; ​遍历字符串​&#xff1a;通过外层循环逐一检查每个字符。​遇到 ? 时处理​&#xff1a; 内层循环遍历小写字母&#xff08;a 到 z&#xff09;。对每个字母检查是否满足&#xff1a; ​与…...

处理vxe-table 表尾数据是单独一个接口,表格tableData数据更新后,需要点击两下,表尾才是正确的

修改bug思路&#xff1a; 分别把 tabledata 和 表尾相关数据 console.log() 发现 更新数据先后顺序不对 settimeout延迟查询表格接口 ——测试可行 升级↑&#xff1a;async await 等接口返回后再开始下一个接口查询 ________________________________________________________…...