C#利用CMD来获取触摸屏保存到FTP里的报警信息与操作记录

该Demo尝试利用C#来读取PLC触摸屏的报警信息和操作日志写入工控机并保存
通过访问FTP的链接,在FTP当中将所需要的文件进行拷贝,复制到指定位置,然后
通过CMD来对触摸屏进行格式转换
该方法可直接实现将FTP里面db文件、evt文件等直接转换成CSV文档,至于可以转换哪些格式,请翻阅触摸屏关于存储ftp文件格式的说明

这份代码是以威纶通触摸屏为模板写的,有需要的朋友可以看看
下面展示一些 内联代码片

// An highlighted block
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace cmd
{
   
    class Program
    {
   
        #region FTP
        private static string host = null;
        private static string user = null;
        private static string pass = null;
        private static FtpWebRequest ftpRequest = null;
        private static FtpWebResponse ftpResponse = null;
        private static Stream ftpStream = null;
        private static int bufferSize = 8192;

        public static bool BinaryMode = true;

        //创建对象
        public Program(string hostIP, string userName, string password)
        {
   
            host = hostIP;
            user = userName;
            pass = password;
        }

        //从FTP获取
        public static void get(string remoteFile, string localFile)
        {
   
            try
            {
   
                //创建FTP请求,将ftp的链接和文件名传入
                FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
                //使用提供的用户名和密码登录FTP服务器 ,这个用户名和密码在触摸屏的说明文档里
                ftpRequest.Credentials = new NetworkCredential(user, pass);
                ftpRequest.UseBinary = BinaryMode;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                //配置FTP请求的类型
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                //与FTP服务器建立返回通信 
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                //获取FTP服务器的响应流
                ftpStream = ftpResponse.GetResponseStream();
                //打开文件流来写入下载的文件 
                FileStream localFileStream = new FileStream(localFile, FileMode.Create);
                //下载数据的缓冲区
                byte[] byteBuffer = new byte[bufferSize];
                int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
                //通过写入缓冲数据来下载文件,直到传输完成 
                try
                {
   
                    while (bytesRead > 0)
                    {
   
                        localFileStream.Write(byteBuffer
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值