以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- FTP都加上了TRY语句,还是会报错 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=192617) |
|
-- 作者:9EQ98 -- 发布时间:2024/7/5 13:50:00 -- FTP都加上了TRY语句,还是会报错 If _FTP_正在下载 = True Then Return True End If _FTP_正在下载 = True \' 下载所有扩展列附件(图片、文件) Dim FTP As New FTPClient FTP.Host = _FTP_Abbr_Host FTP.Password = _FTP_Abbr_Pass FTP.Account = _FTP_Abbr_Acco FTP.Port = _FTP_Abbr_Port FTP.RootDir = _FTP_Abbr_Root FTP.Connect If FTP.Connect = False Then If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP连接失败!" & Date.Now() End If _FTP_正在下载 = False Return False Else If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP目录" & FTP.RootDir & "|" & "FTP启动" & Date.Now() End If End If Dim 成功 As Integer = 0 Dim 失败 As Integer = 0 Dim 跳过 As Integer = 0 Dim 执行 As Integer = 0 Dim 丢失 As Integer = 0 Dim 条件 As String = " And _New_Acc = \'" & _登录人 & "\'" If Functions.Execute("Acc_Into", "{系统管理组}|{报表打印组}") = True Then 条件 = "" End if For Each DT As DataTable In DataTables For Each DC As DataCol In DT.DataCols If DC.ExtendType = ExtendTypeEnum.Images OrElse DC.ExtendType = ExtendTypeEnum.File OrElse DC.ExtendType = ExtendTypeEnum.FileS Then Dim drs As List(Of DataRow) = DT.SQLSelect(DC.Name & " Is Not Null " & 条件) For Each dr As DataRow In drs Dim Files As String = DR(DC.NAME) Dim Values() As String Values = Files.Split(vbCrLf) For Index As Integer = 0 To Values.Length - 1 If _FTP_下载终止 = True Then Return True End If 执行 = 执行 + 1 Dim NetFile As String = Values(Index) If NetFile = "" Then Continue For \' 下一个循环 End If \' 排除那些文件 \' If NetFile.Contains("png") OrElse NetFile.Contains("pg") OrElse NetFile.Contains("ls") Then \' Continue For \' 下一个循环 \' End If Dim LocFile As String = ProjectPath & "\\RemoteFiles\\" & NetFile.Replace("/", "\\") LocFile = LocFile.Replace("\\\\", "\\") If FTP.Connect = False Then \' FTP连接失败时 StatusBar.Message3 = "FTP连接失败!" & Date.Now() _FTP_正在下载 = False Return False End If Try If ftp.FileExists(NetFile) = False Then \'如果存在则下载 丢失 = 丢失 + 1 Continue For \' 下一个循环 End If Catch ex As Exception If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP远程检查异常:" & DT.Name & " " & DC.Name MESS.ComboList = MESS.ComboList & "|" & NetFile MESS.ComboList = MESS.ComboList & "|" & "√" & 成功 & "×" & 失败 & "☆" & 丢失 & "⌒" & 跳过 & "/" & 执行 End If \'Continue For \' 下一个循环 End Try Try If FileSys.FileExists(LocFile) Then Dim NetSize As Integer NetSize = ftp.GetFileSize(NetFile) Dim Locifo As New FileInfo(LocFile) Dim LocSize As Integer = Locifo.Length \'Output.Show(NetSize & " " & LocSize) If NetSize = LocSize Then 跳过 = 跳过 + 1 Continue For \' 下一个循环 End If End If Catch ex As Exception If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP文件比较异常:" & DT.Name & " " & DC.Name MESS.ComboList = MESS.ComboList & "|" & NetFile End If \'Continue For \' 下一个循环 End Try If FTP.Connect = False Then \' FTP连接失败时 StatusBar.Message3 = "FTP连接失败!" & Date.Now() _FTP_正在下载 = False Return False End If If FTP.Connect = True Then Try If ftp.Download(NetFile, LocFile) Then 成功 = 成功 + 1 Else 失败 = 失败 + 1 End If Catch ex As Exception If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP下载异常:" & DT.Name & " " & DC.Name MESS.ComboList = MESS.ComboList & "|" & NetFile End If End Try End If If _FTP_下载终止 = True Then Return True End If Next Next StatusBar.Message3 = "√" & 成功 & "×" & 失败 & "☆" & 丢失 & "⌒" & 跳过 & "/" & 执行 & " " & DT.Name & " " & DC.Name End If Next Next StatusBar.Message3 = "√" & 成功 & "×" & 失败 & "☆" & 丢失 & "⌒" & 跳过 & "|" & 执行 If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & StatusBar.Message3 MESS.ComboList = MESS.ComboList & "|" & "FTP完成下载" End If _FTP_完成下载 = True _FTP_正在下载 = False Return True |
|
-- 作者:有点蓝 -- 发布时间:2024/7/5 14:08:00 -- 提示的意思是集合已经被更改,无法进行遍历处理。这个和ftp应该没有关系,应该是try之外出现的错误 |
|
-- 作者:9EQ98 -- 发布时间:2024/7/5 14:41:00 -- 为什么FTP检查文件是否存在,也会出错.那份文件在FTP文件服务器上是存在的 ftp.FileExists(NetFile) = False 这一句为什么会报错,执行了 Catch ex As Exception 做了记录
Try If ftp.FileExists(NetFile) = False Then \'如果存在则下载 丢失 = 丢失 + 1 Continue For \' 下一个循环 End If Catch ex As Exception If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") MESS.ComboList = MESS.ComboList & "|" & "FTP远程检查异常:" & DT.Name & " " & DC.Name MESS.ComboList = MESS.ComboList & "|" & NetFile MESS.ComboList = MESS.ComboList & "|" & "√" & 成功 & "×" & 失败 & "☆" & 丢失 & "⌒" & 跳过 & "/" & 执行 End If \'Continue For \' 下一个循环 End Try [此贴子已经被作者于2024/7/5 14:42:57编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2024/7/5 14:58:00 -- 看具体什么错误? Try If ftp.FileExists(NetFile) = False Then \'如果存在则下载 丢失 = 丢失 + 1 Continue For \' 下一个循环 End If Catch ex As Exception msgbox(ex.message) ……
|
|
-- 作者:9EQ98 -- 发布时间:2024/7/5 16:44:00 -- msgbox(ex.message) 出现这样的报错提示 对象引用未设置为对象的实例。 其他地方也经常有类似这样的报错
[此贴子已经被作者于2024/7/5 16:45:22编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2024/7/5 16:59:00 -- 不可能啊,除非ftp是空的、 再调试看看 Try msgbox(ftp is nothing) If ftp.FileExists(NetFile) = False Then \'如果存在则下载 丢失 = 丢失 + 1 Continue For \' 下一个循环 End If msgbox("NetFile=" & NetFile) Catch ex As Exception
|
|
-- 作者:9EQ98 -- 发布时间:2024/7/5 23:18:00 -- Try If FTP.Connect = True Then \' FTP连接失败时 If ftp.FileExists(NetFile) = False Then \'如果存在则下载 丢失 = 丢失 + 1 Continue For \' 下一个循环 End If End If Catch ex As Exception Dim IsFTP As Boolean = ftp Is Nothing FileSys.WriteAllText(ProjectPath & "Ftp_Files_Down_Err.Txt", "FTP Is Nothing =" & IsFTP & vbCrLf, True) FileSys.WriteAllText(ProjectPath & "Ftp_Files_Down_Err.Txt", "检查文件存在NetFile =" & NetFile & vbCrLf, True) FileSys.WriteAllText(ProjectPath & "Ftp_Files_Down_Err.Txt", ex.message & vbCrLf, True) If Forms("登录日志").Opened = True AndAlso Forms("登录日志").Controls.Contains("DT_List") = True Then Dim MESS As WinForm.ListBox = Forms("登录日志").Controls("DT_List") Dim txt As String = DT.Name & " " & DC.Name If MESS.ComboList.Contains(txt) = False Then MESS.ComboList = MESS.ComboList & "|" & txt End if MESS.ComboList = MESS.ComboList & "|检查异常:" & NetFile \'msgbox(ex.message) End If 以下结果: NetFile=/ST/YPJH/OX-2024-05-020/1.png FTP Is Nothing: False /ST/YPJH/OX-2024-05-020/1.png FTP Is Nothing =False 检查文件存在NetFile =/ST/YPJH/ST-2024-02-002/1/File/ST02037XN样品计划.xls Object reference not set to an instance of an object. FTP Is Nothing =False 检查文件存在NetFile =/ST/Morning/3566蓝色横线丝网.png Object reference not set to an instance of an object. FTP Is Nothing =False 检查文件存在NetFile =/ST/YPJH/ST-2024-06-026/4.png Object reference not set to an instance of an object. FTP Is Nothing =False 检查文件存在NetFile =/ST/YPJH/ST-2024-06-039/65.png Object reference not set to an instance of an object. FTP Is Nothing =False 检查文件存在NetFile =/ST/354.png Object reference not set to an instance of an object.
[此贴子已经被作者于2024/7/5 23:19:39编辑过]
|
|
-- 作者:有点蓝 -- 发布时间:2024/7/6 8:57:00 -- 这样调试看看输出什么错误结果
|