找回密码
 加入
搜索
查看: 2067|回复: 2

[网络通信] 如何监听共享服务器上的某个文件夹?

[复制链接]
发表于 2011-2-9 15:24:39 | 显示全部楼层 |阅读模式
不知道大家是否用AutoIt写过一些监听的程序,我想实现监听局域网内一个贡献的服务器上的指定的文件夹!目前毫无头绪,希望有经验的指教一二.....
发表于 2011-2-9 15:36:22 | 显示全部楼层
不明白楼主的监听包括哪些,是否需要监听后有所动作,我这里有一个用来中转不同平台文件的一个小程序,希望对楼主有用:

#include<file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=D:\桌面\UDF\Form2.kxf

$config = @ScriptDir & "\config.dat"
$password = IniRead($config, "config", "pwd", "")
$logpath = IniRead($config, "config", "path", "") ;netware生成的文件的路径;
$srvPath = IniRead($config, "config", "Srvpath", "") ;SFC服务器的目标目录
$_auto = IniRead($config, "config", "autostart", "")

$Form2 = GUICreate("窗体1", 504, 471, -1, -1)
$List1 = GUICtrlCreateList("", 8, 32, 377, 396)
$start = GUICtrlCreateButton("启      动", 400, 344, 89, 33)
$save = GUICtrlCreateButton("保     存", 400, 392, 89, 33)
$auto = GUICtrlCreateCheckbox(" 自动运行", 400, 296, 78, 33)
If $_auto = "1" Then
        GUICtrlSetState($auto, $GUI_CHECKED)
Else
        GUICtrlSetState($auto, $GUI_UnCHECKED)
EndIf
$Group1 = GUICtrlCreateGroup("监视目录情况", 0, 16, 393, 417)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Input1 = GUICtrlCreateInput($srvPath, 72, 440, 300, 21)
$Label1 = GUICtrlCreateLabel("目录路径:", 8, 442, 64, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        $pwd = InputBox("请输入退出密码:", "请输入退出密码:", "", "*")
                        If Not $pwd <> $password Then
                                MsgBox(0, "恭喜!", "密码正确!按确认键退出!")
                                Exit
                        Else
                                MsgBox(16, "对不起!", "你输入的密码有误!")
                        EndIf
                Case $start
                        monitor()
                Case $save
                        IniWrite($config, "config", "Srvpath", GUICtrlRead($Input1))
                        If GUICtrlRead($auto) = $GUI_CHECKED Then
                                IniWrite($config, "config", "autostart", "1")
                                If Not FileExists(@StartupDir & "\DOS监视器.lnk") Then
                                        FileCreateShortcut(@AutoItExe, @StartupDir & "\DOS监视器.lnk")
                                EndIf
                        Else
                                IniWrite($config, "config", "autostart", "0")
                                If FileExists(@StartupDir & "\DOS监视器.lnk") Then
                                        FileDelete(@StartupDir & "\DOS监视器.lnk")
                                EndIf
                        EndIf
        EndSwitch
WEnd

Func monitor()
        If Not FileExists($logpath) Then
                MsgBox(16, "警告!", "没有连接到Netware服务器" & @CRLF & "或者Netware服务器不在线!请点击确认并映射网络驱动器后再次点击启动进行尝试!")
        Else
                While 1
                        $txt = _FileListToArray($logpath, "*.txt", 1)
                        If Not @error Then
                                For $i = 0 To $txt[$i]
                                        If FileMove($logpath & "\" & $txt[$i], $srvPath & "\00E066" & $txt[$i], 9) Then
                                                print(FileRead($srvPath & "\" & $txt[$i]))
                                        Else
                                                print($logpath & "\" & $txt[$i] & "文件移动失败!")
                                        EndIf
                                Next
                        Else
                                Sleep(2000)
                        EndIf
                WEnd
        EndIf
EndFunc   ;==>monitor

Func print($value)
        GUICtrlSetData($List1, $value & @CRLF)
EndFunc   ;==>print


config.dat里面的内容如下:

[config]
pwd=test
path=\\192.168.1.2\log
srvpath=\\192.168.1.240\public
autostart=1
 楼主| 发表于 2011-2-9 16:15:13 | 显示全部楼层
非常感谢楼上的支持,大概我的思路应该有了一些了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-17 16:51 , Processed in 0.077410 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表