• 大小: 32.69MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-08-06
  • 语言: C#
  • 标签: Socket  

资源简介

C#使用FileSystemWatcher来监控指定文件夹,并使用TCP/IP协议通过Socket发送到另外指定文件夹

资源截图

代码片段和文件信息

using System;
using System.Data;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectoryWatch.Class;
using NewLife.Data;
using NewLife.Log;
using NewLife.Net;
using NewLife.Net.Handlers;

namespace DirectoryWatch
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
        }

        private static int remotePort = 0;
        private static int localPort = 0;
        private static string remoteIP = ““;
        private FileSystemWatcher watcher;
        private NetServer server;
        private void Btn_dirbd_Click(object sender EventArgs e)
        {
            using (var folderBrowser = new FolderBrowserDialog())
            {
                if (folderBrowser.ShowDialog() != DialogResult.OK) return;
                Program.SendDir = folderBrowser.SelectedPath;
                if (!Directory.Exists(Program.SendDir))
                {
                    MessageBox.Show(@“所选路径不存在或无权访问“ @“错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                if (string.Equals(Program.SaveDir.ToLower() Program.SendDir.ToLower()))
                {
                    MessageBox.Show(@“自动接收文件夹和自动发送文件夹不能是同一个文件夹“ @“错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                txt_localPath.Text = folderBrowser.SelectedPath;
                Program.SendDir = folderBrowser.SelectedPath;
            }
        }

        private void Btn_saveDic_Click(object sender EventArgs e)
        {
            using (var folderBrowser = new FolderBrowserDialog())
            {
                if (folderBrowser.ShowDialog() != DialogResult.OK) return;
                Program.SaveDir = folderBrowser.SelectedPath;
                if (!Directory.Exists(Program.SendDir))
                {
                    MessageBox.Show(@“所选路径不存在或无权访问“ @“错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                if (string.Equals(Program.SaveDir.ToLower() Program.SendDir.ToLower()))
                {
                    MessageBox.Show(@“自动接收文件夹和自动发送文件夹不能是同一个文件夹“ @“错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                txt_remoteDir.Text = folderBrowser.SelectedPath;
                Program.SaveDir = folderBrowser.SelectedPath;
            }
        }

private void Btn_Start_Click(object sender EventArgs e)
{
    int.TryParse(txt_remotePort.Text out remotePort);
    int.TryParse(txt_localPort.Text out localPort);
    if (string.IsNullOrEmpty(txt_remoteIP.Text.Trim()))
    {
        MessageBox.Show(@“请填写远程服务器IP“ @“错误“ MessageBoxButtons.OK MessageBoxIcon.Error);
        return;
    }
    remoteIP = txt_remoteIP.Text.Trim();
    if (remotePort == 0)
    {
        MessageBox.Show

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     79872  2019-06-12 10:26  .vs\DirectoryWatch\v16\.suo

     文件          0  2019-05-27 18:43  .vs\DirectoryWatch\v16\Server\sqlite3\db.lock

     文件    1245184  2019-06-12 10:26  .vs\DirectoryWatch\v16\Server\sqlite3\storage.ide

     文件       1761  2019-06-08 21:56  DirectoryWatch\App.config

     文件       9063  2019-06-08 21:56  DirectoryWatch\Class\SQLiteHelper.cs

     文件       6765  2019-06-08 21:56  DirectoryWatch\DirectoryWatch.csproj

     文件        231  2019-06-08 21:56  DirectoryWatch\DirectoryWatch.csproj.user

     文件      13967  2019-06-12 10:13  DirectoryWatch\MainFrm.cs

     文件      10163  2019-06-12 09:34  DirectoryWatch\MainFrm.Designer.cs

     文件       5817  2019-06-12 09:34  DirectoryWatch\MainFrm.resx

     文件       1423  2019-06-11 18:09  DirectoryWatch\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       8428  2019-06-11 18:11  DirectoryWatch\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-06-12 10:13  DirectoryWatch\obj\Debug\DirectoryWatch.csproj.CopyComplete

     文件         42  2019-06-11 18:07  DirectoryWatch\obj\Debug\DirectoryWatch.csproj.CoreCompileInputs.cache

     文件       1956  2019-06-11 18:07  DirectoryWatch\obj\Debug\DirectoryWatch.csproj.FileListAbsolute.txt

     文件       1014  2019-06-12 09:35  DirectoryWatch\obj\Debug\DirectoryWatch.csproj.GenerateResource.cache

     文件      57440  2019-06-11 18:11  DirectoryWatch\obj\Debug\DirectoryWatch.csprojAssemblyReference.cache

     文件      26112  2019-06-12 10:13  DirectoryWatch\obj\Debug\DirectoryWatch.exe

     文件        180  2019-06-12 09:35  DirectoryWatch\obj\Debug\DirectoryWatch.MainFrm.resources

     文件      52736  2019-06-12 10:13  DirectoryWatch\obj\Debug\DirectoryWatch.pdb

     文件        180  2019-06-11 09:56  DirectoryWatch\obj\Debug\DirectoryWatch.Properties.Resources.resources

     文件        647  2019-06-08 21:56  DirectoryWatch\packages.config

     文件        798  2019-06-08 21:56  DirectoryWatch\Program.cs

     文件       1344  2019-06-11 18:11  DirectoryWatch\Properties\AssemblyInfo.cs

     文件       2841  2019-05-27 18:43  DirectoryWatch\Properties\Resources.Designer.cs

     文件       5612  2019-05-27 18:43  DirectoryWatch\Properties\Resources.resx

     文件       1101  2019-05-27 18:43  DirectoryWatch\Properties\Settings.Designer.cs

     文件        249  2019-05-27 18:43  DirectoryWatch\Properties\Settings.settings

     文件       9491  2019-06-08 21:56  packages\Entityframework.6.2.0\.signature.p7s

     文件        209  2019-06-08 21:56  packages\Entityframework.6.2.0\content\net40\App.config.transform

............此处省略664个文件信息

评论

共有 条评论