16,554
社区成员
发帖
与我相关
我的任务
分享
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Control.CheckForIllegalCrossThreadCalls = False
Dim ftpReq As System.Net.FtpWebRequest = Nothing
Dim ftpRes As System.Net.FtpWebResponse = Nothing
ftpReq = System.Net.WebRequest.Create("ftp://www.1234abcd.com") '连接指定服务器
ftpReq.Credentials = New System.Net.NetworkCredential("ftpid", "ftppw")
ftpReq.Method = System.Net.WebRequestMethods.Ftp.ListDirectory
ftpReq.KeepAlive = False
ftpReq.UsePassive = False
ftpReq.Timeout = 10000 '10秒连接不上则超时
ftpRes = ftpReq.GetResponse() '更新程序现在就卡在这里
Dim strContent As String = ""
Dim content(1024) As Byte
Dim index_a As Integer = 0
Dim bufferLen As Integer = 0
index_a = ftpRes.GetResponseStream.Read(content, 0, content.Length)
bufferLen = bufferLen + index_a
While index_a > 0
index_a = ftpRes.GetResponseStream.Read(content, 0, content.Length)
bufferLen = bufferLen + index_a
End While
strContent = strContent & System.Text.Encoding.UTF8.GetString(content, 0, bufferLen)
Dim sk As Integer = 0
If InStr(strContent, "web.config") > 0 Then '屏蔽掉列表内不需要的文件名
strContent = Replace(strContent, "web.config", "")
sk = 2
Else
sk = 1
End If
strContent = Replace(strContent, "web.config", "")
Dim AR() As String = Split(strContent, vbCrLf) '获取需要更新的文件到数组
Dim k As Integer = UBound(AR) - sk
ProgressBarX2.Value = 0
ProgressBarX2.Minimum = 0
ProgressBarX2.Maximum = k
For i = 0 To k
'myWebClient = New WebClient
sv = "http://www.1234abcd.com:8080/Update/" + AR(i)
Label4.Text = "正在更新:\..." + AR(i)
myWebClient = New WebClient
myWebClient.DownloadFile(New Uri(sv), Application.StartupPath + "\" + AR(i)) 'HTTP下载
'My.Computer.Network.DownloadFile(so + "/" + AR(i), sn + "\" + AR(i), "ftpid", "ftppw.", False, 9999999, True) 'FTP下载
ProgressBarX2.Value += 1
Next
Label4.Text = "更新完毕..."
WriteINI("Version", "Ver", ver2, path1)
WriteINI("UDate", "Date", Now, path1)
Pause(1)
If Dir(Application.StartupPath + "\EBS.exe") <> "" Then
Dim EBS As New Process
EBS.StartInfo.FileName = Application.StartupPath + "\EBS.exe"
EBS.Start()
Else
MessageBox.Show("未能找到主程序" & Chr(10) & "请重新安装客户端!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
End
End If
Me.Close()
Me.Dispose()
Me.BackgroundWorker1.Dispose()
End Sub