执行代码:
Dim dr As DataRow = DataTables("文件存储窗口_Table4").DataRows(0)
Dim html As String = _UserFtID & _UserName
Dim htmldr As DataRow
htmldr = DataTables("目录表").SQLFind("目录名 = '" & html & "' and 一级目录 = '个人文件' and 二级目录 is null")
Dim htmlid As Integer = htmldr("_Identify")
Functions.AsyncExecute("T同步工作文件夹",dr("工作目录"),"/个人文件/" & html,htmlid)
自定义函数“T同步工作文件夹”代码
Dim ml As String = Args(0) '要同步的本地工作目录
Dim htlj As String = Args(1) 'Ftp文件夹路径
Dim htmlid As Integer = Args(2) '后台目录ID
'生成本地文件信息表和后台文件信息表
Dim cmd As new SQLCommand
Dim htwjdt As DataTable
cmd.C
cmd.CommandText = "select * fr om {文件表} where [_Identify] is null"
htwjdt = cmd.ExecuteReader(True) '记得将参数设置为True
Dim bdwjdt As DataTable
Dim cmd1 As new SQLCommand
cmd1.C
cmd1.CommandText = "select * fro m {本机文件表} where [_Identify] is null"
bdwjdt = cmd1.ExecuteReader(True) '记得将参数设置为True
Dim mldr As DataRow
mldr = DataTables("文件存储窗口_Table4").Find("硬盘ID = '" & harddiskid & "'")
If mldr Is Nothing Then
Return Nothing
End If
Dim html As String = _UserFtID & _UserName
DataTables("目录表").LoadFilter = "父目录ID = " & htmlid & " and 一级目录 = '个人文件' and 二级目录 = '" & html & "' and 三级目录 is null"
DataTables("目录表").Load(False)
htwjdt.LoadFilter = "父目录ID = " & htmlid '加载ftp文件信息
htwjdt.Load()
bdwjdt.LoadFilter = "父目录ID = " & htmlid '加载本地文件信息
bdwjdt.Load()
Dim mlwjs As new List(of String)
For Each File As String In FileSys.GetFiles(ml) '得到本地当前目录所有文件名,不含路径
If mlwjs.Contains(FileSys.GetName(file)) = False Then
mlwjs.Add(FileSys.GetName(file))
End If
Next
'更新文件
For Each File As String In FileSys.GetFiles(ml)
Dim ifo As new FileInfo(file)
Dim htwjdr As DataRow = htwjdt.Find("文件名 + 后辍 = '" & ifo.Name & "'")
Dim bdwjdr As DataRow
Dim wjm As String = ifo.Name.Remove(Ifo.Name.Length - ifo.Extension.Length)
If htwjdr Is Nothing Then
Functions.Execute("T同步上传或更新文件",wjm,Ifo.Extension,htlj & "/" & Ifo.Name,file,htwjdt,htwjdr,bdwjdt,bdwjdr,htmlid,mldr("_Identify"))
Else
bdwjdr = bdwjdt.Find("文件ID = " & htwjdr("_Identify") & " and 硬盘行ID = " & mldr("_Identify"))
If bdwjdr IsNot Nothing Then
If format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") > bdwjdr("本机修改时间") Then
Functions.Execute("T同步上传或更新文件",wjm,Ifo.Extension,htlj & "/" & Ifo.Name,file,htwjdt,htwjdr,bdwjdt,bdwjdr,htmlid,mldr("_Identify"))
End If
End If
End If
Next
'下载新文件
For Each htdr As DataRow In htwjdt.DataRows
If mlwjs.Contains(htdr("文件名") & htdr("后辍")) = False Then
Dim xzpd As Boolean
xzpd = Functions.Execute("ftp下载文件",htlj & htdr("文件名") & htdr("后辍"),ml & "\" & htdr("文件名") & htdr("后辍"))
If xzpd = True Then
Dim bdwjdr As DataRow = bdwjdt.AddNew()
bdwjdr("硬盘行ID") = mldr("_Identify")
bdwjdr("文件ID") = htdr("_Identify")
bdwjdr("父目录ID") = htdr("父目录ID")
bdwjdr("本机修改时间") = htdr("修改时间")
End If
End If
Next
bdwjdt.Save()
'遍历同步文件夹下的目录
Dim htmls As new List(of String()) '后台同步目录下的所有子目录
htmls = DataTables("目录表").GetValues("_Identify|目录名")
Dim html1s As new List(of String) '后台同步目录下的子目录无目录ID
html1s = DataTables("目录表").GetValues("目录名")
Dim bdmls As new List(of String) '文件夹下的所有目录
For Each dir As String In FileSys.GetDirectories(ml) '得到文件夹下的所有目录,同时新增ftp目录并同步
Dim mlname As String = dir.SubString(ml.Length + 1)
If bdmls.Contains(mlname) = False Then
bdmls.Add(mlname)
End If
If html1s.Contains(mlname) = False Then
Dim xid As Integer
xid = Functions.Execute("ftp创建文件夹",mlname,htmlid,"个人文件\" & html)
Functions.Execute("T同步工作文件夹",dir,htlj & "/" & mlname,xid)
Else
For Each hml As String() In htmls
If hml(1) = mlname Then
Functions.Execute("T同步工作文件夹",dir,htlj & "/" & mlname,hml(0))
End If
Next
End If
Next
'新增本地目录并下载
For Each hml As String() In htmls
If bdmls.Contains(hml(1)) = False Then
Dim hxlm As String = ml & "\" & hml(1)
Dim xhtlj As String = htlj & hml(1) & "/"
Functions.Execute("T同步下载新文件夹",hml(0),hml(1),hxlm,htwjdt,xhtlj,html,bdwjdt,mldr("_Identify"))
End If
Next
bdwjdt.Save()