VB的INET控件写FTP的问题
DimobjfsoAsNewFileSystemObjectPrivateSubCommand1_Click()IfList1.List(0)=""ThenMsgBox"...
Dim objfso As New FileSystemObject
Private Sub Command1_Click()
If List1.List(0) = "" Then
MsgBox "当前没有可供下载的NC程式,请确认", vbCritical + vbOKOnly, "警告"
Exit Sub
ElseIf List1.List(0) <> "" Then
If objfso.FolderExists("d:\nctemp\") = True Then
objfso.DeleteFolder "d:\nctemp"
MkDir "d:\nctemp"
ElseIf objfso.FolderExists("d:\nctemp\") = False Then
MkDir "d:\nctemp"
End If
For i = 0 To List1.ListCount - 1
Inet6.Cancel
Inet6.Execute , "get MZ/" & List1.List(i) & " D:\NCTEMP" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
Next
End If
MsgBox "ok"
End Sub
Private Sub Command2_Click()
If Option1.Value = False And Option2.Value = False And Option3.Value = False Then
MsgBox "请选择要上传的机器"
Exit Sub
ElseIf Option1.Value = True Then
For i = 0 To List1.ListCount - 1
Inet4.Cancel
Inet4.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet4.StillExecuting
DoEvents
Loop
Inet4.Execute , "CLOSE"
Inet4.Execute , "QUIT"
Next
ElseIf Option2.Value = True Then
For i = 0 To List1.ListCount - 1
Inet5.Cancel
Inet5.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet5.StillExecuting
DoEvents
Loop
Inet5.Execute , "CLOSE"
Inet5.Execute , "QUIT"
Next
ElseIf Option3.Value = True Then
For i = 0 To List1.ListCount - 1
Inet6.Cancel
Inet6.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
Next
End If
MsgBox OK
End Sub
上面的代码是我程序当中的某段代码,意思是将6号FTP的资料的资料下载到本地的D:\NCTEMP目录下,然后再根据Option控件的选择,把D:\NCTEMP的资料上传到3号或4号或5号的FTP中去
但是当我运行的时候发现,如下问题
明明下载下来应该是5个文件但是他下载下来的只有4个,第5个下载的时候就卡死了,当TIMEOUT后VB就非法关闭了,打开D:\NCTEMP目录去看发现第5个文件下载大小明显不对.变小了,小很多.下载有这种问题,上传也有同样的问题.
望高手答疑解惑,万分感谢
感觉楼下的方法不怎么稳定,我在执行第二笔资料的时候还是会出错 ,多运行几次就会卡住 展开
Private Sub Command1_Click()
If List1.List(0) = "" Then
MsgBox "当前没有可供下载的NC程式,请确认", vbCritical + vbOKOnly, "警告"
Exit Sub
ElseIf List1.List(0) <> "" Then
If objfso.FolderExists("d:\nctemp\") = True Then
objfso.DeleteFolder "d:\nctemp"
MkDir "d:\nctemp"
ElseIf objfso.FolderExists("d:\nctemp\") = False Then
MkDir "d:\nctemp"
End If
For i = 0 To List1.ListCount - 1
Inet6.Cancel
Inet6.Execute , "get MZ/" & List1.List(i) & " D:\NCTEMP" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
Next
End If
MsgBox "ok"
End Sub
Private Sub Command2_Click()
If Option1.Value = False And Option2.Value = False And Option3.Value = False Then
MsgBox "请选择要上传的机器"
Exit Sub
ElseIf Option1.Value = True Then
For i = 0 To List1.ListCount - 1
Inet4.Cancel
Inet4.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet4.StillExecuting
DoEvents
Loop
Inet4.Execute , "CLOSE"
Inet4.Execute , "QUIT"
Next
ElseIf Option2.Value = True Then
For i = 0 To List1.ListCount - 1
Inet5.Cancel
Inet5.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet5.StillExecuting
DoEvents
Loop
Inet5.Execute , "CLOSE"
Inet5.Execute , "QUIT"
Next
ElseIf Option3.Value = True Then
For i = 0 To List1.ListCount - 1
Inet6.Cancel
Inet6.Execute , "put d:\nctemp\" & List1.List(i) & " /" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
Next
End If
MsgBox OK
End Sub
上面的代码是我程序当中的某段代码,意思是将6号FTP的资料的资料下载到本地的D:\NCTEMP目录下,然后再根据Option控件的选择,把D:\NCTEMP的资料上传到3号或4号或5号的FTP中去
但是当我运行的时候发现,如下问题
明明下载下来应该是5个文件但是他下载下来的只有4个,第5个下载的时候就卡死了,当TIMEOUT后VB就非法关闭了,打开D:\NCTEMP目录去看发现第5个文件下载大小明显不对.变小了,小很多.下载有这种问题,上传也有同样的问题.
望高手答疑解惑,万分感谢
感觉楼下的方法不怎么稳定,我在执行第二笔资料的时候还是会出错 ,多运行几次就会卡住 展开
1个回答
展开全部
应该把
Inet6.Cancel
和
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
移到循环外面,比如:
Inet6.Cancel
For i = 0 To List1.ListCount - 1
Inet6.Execute , "get MZ/" & List1.List(i) & " D:\NCTEMP" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Next
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
下面的上传文件也一样。
FTP的get命令和put命令是可以连续执行的,无需下载一个文件就退出,然后又再登录下载下一个文件,这样不但效率低,而且很可能就是在这个不断登录的过程中造成文件下载异常。
限于条件,以上语句我无法测试,你自己试试看对不对。
Inet6.Cancel
和
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
移到循环外面,比如:
Inet6.Cancel
For i = 0 To List1.ListCount - 1
Inet6.Execute , "get MZ/" & List1.List(i) & " D:\NCTEMP" & List1.List(i)
Do While Inet6.StillExecuting
DoEvents
Loop
Next
Inet6.Execute , "CLOSE"
Inet6.Execute , "QUIT"
下面的上传文件也一样。
FTP的get命令和put命令是可以连续执行的,无需下载一个文件就退出,然后又再登录下载下一个文件,这样不但效率低,而且很可能就是在这个不断登录的过程中造成文件下载异常。
限于条件,以上语句我无法测试,你自己试试看对不对。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询