资料查了不少,没做出来。。。。。。 高手帮忙。。。。
http://topic.csdn.net/u/20090317/10/89181bba-73f2-4857-992c-337e704238ed.html
这一贴也一并结。
500分,现在一贴只能发100分,测试没问题开剩余4贴结分。
12 个解决方案
#1
保持解释下 ,保证当时下载的文件夹结构和名字一致就可以了,不做实时更行。
高手们帮个忙吧。。。
高手们帮个忙吧。。。
#2
帮顶,学习,等待高手...
#3
这个不太难,先获取文件列表,在本地建立跟FTP一样的目录结构,然后一个个文件下载就是了。
明天有时间的话给你把代码贴上来。
明天有时间的话给你把代码贴上来。
#4
oFTP =
New nBitFTP.clsFTP()第三方控件。nBit Information Technologies
oFTP.Host = "www. 1234.com"
oFTP.UserName = "1234"
oFTP.Password = "1234"
Me.ListBox1.Items.Clear()
Dim wjj As New System.Collections.ArrayList
If oFTP.connect() = True Then '创建连接
If oFTP.GetDirectoryListing("*.*") = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." Then
wjj.Add(Wmc)
End If
Next
End If
End If
Dim Js As Int16 = 0
While wjj.Count <> Js
Js = wjj.Count
If oFTP.connect() = True Then '创建连接
For xh As Int32 = 0 To wjj.Count - 1
If oFTP.GetDirectoryListing(wjj(xh)) = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True Then
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." _
And wjj.Contains(wjj(xh) & "/" & Wmc) = False Then
wjj.Add(wjj(xh) & "/" & Wmc)
End If
End If
Next
End If
Next
End If
End While
For xh As Int32 = 0 To wjj.Count - 1
Me.ListBox1.Items.Add(wjj(xh))
If IO.Directory.Exists(Me.TextBoxsave.Text & "/" & wjj(xh)) = False Then
IO.Directory.CreateDirectory(Me.TextBoxsave.Text & "/" & wjj(xh))
End If
Dgwj(wjj(xh))
Next
Me.ToolStripProgressBar1.Visible = True
Dim Xzjs As Int32 = 0
Me.ToolStripProgressBar1.Maximum = Me.DataGridVieFile.Rows.Count - 1
Dim Xzjl As New System.Collections.SortedList
For xh As Int32 = 0 To Me.DataGridVieFile.Rows.Count - 1
Dim Wmc As String = Me.DataGridVieFile.Rows(xh).Cells(0).Value
Dim Bdwj As String = Me.TextBoxsave.Text & "/" & Wmc
Dim Wjcd As Int32 = Me.DataGridVieFile.Rows(xh).Cells(2).Value
Dim Xgsj As Date = Me.DataGridVieFile.Rows(xh).Cells(3).Value
If IO.File.Exists(Bdwj) = False Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
Else
If New IO.FileInfo(Bdwj).Length < Wjcd Or New IO.FileInfo(Bdwj).LastWriteTime < Xgsj Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
End If
End If
Me.ToolStripProgressBar1.Value = xh
Next
Me.ToolStripProgressBar1.Maximum = Xzjl.Count - 1
For xh As Int32 = 0 To Xzjl.Count - 1
Me.TextBoxurl.Text = "www.1234.com/" & Xzjl.GetKey(xh)
Try
Dim Dc As New Uri("ftp://1234.com/" & Xzjl.GetKey(xh))
My.Computer.Network.DownloadFile(Dc, _
Xzjl.GetByIndex(xh), "1234", "1234", False, 500, True, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/失败.txt", Xzjl.GetKey(xh) & Chr(13) & Chr(10), False)
' Exit Sub
End Try
Me.ToolStripProgressBar1.Value = xh
Me.Label1下载数量.Text = "下载总数:" & Xzjs & " 剩余:" & Xzjs - xh
Next
Me.ToolStripProgressBar1.Visible = False
ToolStripStatusLabel备份.Text = "备份完成"
使用了第三方的控件:
nBitFTP.clsFTP 可以完全按照FTP的目录下载。
oFTP.Host = "www. 1234.com"
oFTP.UserName = "1234"
oFTP.Password = "1234"
Me.ListBox1.Items.Clear()
Dim wjj As New System.Collections.ArrayList
If oFTP.connect() = True Then '创建连接
If oFTP.GetDirectoryListing("*.*") = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." Then
wjj.Add(Wmc)
End If
Next
End If
End If
Dim Js As Int16 = 0
While wjj.Count <> Js
Js = wjj.Count
If oFTP.connect() = True Then '创建连接
For xh As Int32 = 0 To wjj.Count - 1
If oFTP.GetDirectoryListing(wjj(xh)) = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True Then
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." _
And wjj.Contains(wjj(xh) & "/" & Wmc) = False Then
wjj.Add(wjj(xh) & "/" & Wmc)
End If
End If
Next
End If
Next
End If
End While
For xh As Int32 = 0 To wjj.Count - 1
Me.ListBox1.Items.Add(wjj(xh))
If IO.Directory.Exists(Me.TextBoxsave.Text & "/" & wjj(xh)) = False Then
IO.Directory.CreateDirectory(Me.TextBoxsave.Text & "/" & wjj(xh))
End If
Dgwj(wjj(xh))
Next
Me.ToolStripProgressBar1.Visible = True
Dim Xzjs As Int32 = 0
Me.ToolStripProgressBar1.Maximum = Me.DataGridVieFile.Rows.Count - 1
Dim Xzjl As New System.Collections.SortedList
For xh As Int32 = 0 To Me.DataGridVieFile.Rows.Count - 1
Dim Wmc As String = Me.DataGridVieFile.Rows(xh).Cells(0).Value
Dim Bdwj As String = Me.TextBoxsave.Text & "/" & Wmc
Dim Wjcd As Int32 = Me.DataGridVieFile.Rows(xh).Cells(2).Value
Dim Xgsj As Date = Me.DataGridVieFile.Rows(xh).Cells(3).Value
If IO.File.Exists(Bdwj) = False Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
Else
If New IO.FileInfo(Bdwj).Length < Wjcd Or New IO.FileInfo(Bdwj).LastWriteTime < Xgsj Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
End If
End If
Me.ToolStripProgressBar1.Value = xh
Next
Me.ToolStripProgressBar1.Maximum = Xzjl.Count - 1
For xh As Int32 = 0 To Xzjl.Count - 1
Me.TextBoxurl.Text = "www.1234.com/" & Xzjl.GetKey(xh)
Try
Dim Dc As New Uri("ftp://1234.com/" & Xzjl.GetKey(xh))
My.Computer.Network.DownloadFile(Dc, _
Xzjl.GetByIndex(xh), "1234", "1234", False, 500, True, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/失败.txt", Xzjl.GetKey(xh) & Chr(13) & Chr(10), False)
' Exit Sub
End Try
Me.ToolStripProgressBar1.Value = xh
Me.Label1下载数量.Text = "下载总数:" & Xzjs & " 剩余:" & Xzjs - xh
Next
Me.ToolStripProgressBar1.Visible = False
ToolStripStatusLabel备份.Text = "备份完成"
使用了第三方的控件:
nBitFTP.clsFTP 可以完全按照FTP的目录下载。
#5
http://www.west263.com/www/info/32993-1.htm
#6
用自带的FtpWebRequest 类试试,流程可以参考三楼说的,先得到一个列表,然后根据列表下载文件
以下是关于FtpWebRequest 类的MSDN参考
http://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest(VS.80).aspx
以下是关于FtpWebRequest 类的MSDN参考
http://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest(VS.80).aspx
#7
http://blog.csdn.net/Going1981/archive/2009/04/23/4103199.aspx
类里有异步下载的方法,下载进度changed事件、Completed事件都有,真是太好用了。
下面的代码可以将指定FTP的目录及下面所有子目录复制到本地,你自己加入下载的方法吧。
'先引用上面的类,或者直接Copy到项目里 (拿来主义 =。=|| )
Private Sub CreateFloders(ByVal sourcepath As String, ByVal savepath As String)
obj.GotoDirectory(sourcepath)
Dim dirlist As FileStruct() = obj.ListDirectories '获取目录列表
Dim dir As String = ""
If sourcepath.IndexOf("\") > 0 Then
dir = savepath & sourcepath.Substring(sourcepath.LastIndexOf("\"))
Else
dir = savepath & sourcepath
End If
System.IO.Directory.CreateDirectory(dir) '在本地创建目录
For i As Integer = 0 To dirlist.Length - 1
System.IO.Directory.CreateDirectory(dir & "\" & dirlist(i).Name)
obj.GotoDirectory(dirlist(i).Name)
Dim subdirlist As FileStruct() = obj.ListDirectories '获取子目录
If subdirlist.Length > 0 Then
CreateFloders(sourcepath & "\" & dirlist(i).Name, dir) '如果有子目录,递归
obj.GotoDirectory(sourcepath) '返回上级目录
End If
Next
End Sub
调用方法:
Private WithEvents obj As New clsFTP
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
obj.Uri = New Uri("ftp:\\124.193.***.***:**")
obj.UserName = "myuser"
obj.Password = "************"
CreateFloders(".\test", "D:\") '将FTP主目录\test 复制到本地D:\下
'obj.DownloadFileAsync("bsmain_runtime.log", "C:\", "1.txt")
'AddHandler obj.DownloadDataCompleted, AddressOf test
End Sub
#8
我试试。
#10
学习
#11
帮顶
#12
学习啊
#1
保持解释下 ,保证当时下载的文件夹结构和名字一致就可以了,不做实时更行。
高手们帮个忙吧。。。
高手们帮个忙吧。。。
#2
帮顶,学习,等待高手...
#3
这个不太难,先获取文件列表,在本地建立跟FTP一样的目录结构,然后一个个文件下载就是了。
明天有时间的话给你把代码贴上来。
明天有时间的话给你把代码贴上来。
#4
oFTP =
New nBitFTP.clsFTP()第三方控件。nBit Information Technologies
oFTP.Host = "www. 1234.com"
oFTP.UserName = "1234"
oFTP.Password = "1234"
Me.ListBox1.Items.Clear()
Dim wjj As New System.Collections.ArrayList
If oFTP.connect() = True Then '创建连接
If oFTP.GetDirectoryListing("*.*") = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." Then
wjj.Add(Wmc)
End If
Next
End If
End If
Dim Js As Int16 = 0
While wjj.Count <> Js
Js = wjj.Count
If oFTP.connect() = True Then '创建连接
For xh As Int32 = 0 To wjj.Count - 1
If oFTP.GetDirectoryListing(wjj(xh)) = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True Then
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." _
And wjj.Contains(wjj(xh) & "/" & Wmc) = False Then
wjj.Add(wjj(xh) & "/" & Wmc)
End If
End If
Next
End If
Next
End If
End While
For xh As Int32 = 0 To wjj.Count - 1
Me.ListBox1.Items.Add(wjj(xh))
If IO.Directory.Exists(Me.TextBoxsave.Text & "/" & wjj(xh)) = False Then
IO.Directory.CreateDirectory(Me.TextBoxsave.Text & "/" & wjj(xh))
End If
Dgwj(wjj(xh))
Next
Me.ToolStripProgressBar1.Visible = True
Dim Xzjs As Int32 = 0
Me.ToolStripProgressBar1.Maximum = Me.DataGridVieFile.Rows.Count - 1
Dim Xzjl As New System.Collections.SortedList
For xh As Int32 = 0 To Me.DataGridVieFile.Rows.Count - 1
Dim Wmc As String = Me.DataGridVieFile.Rows(xh).Cells(0).Value
Dim Bdwj As String = Me.TextBoxsave.Text & "/" & Wmc
Dim Wjcd As Int32 = Me.DataGridVieFile.Rows(xh).Cells(2).Value
Dim Xgsj As Date = Me.DataGridVieFile.Rows(xh).Cells(3).Value
If IO.File.Exists(Bdwj) = False Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
Else
If New IO.FileInfo(Bdwj).Length < Wjcd Or New IO.FileInfo(Bdwj).LastWriteTime < Xgsj Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
End If
End If
Me.ToolStripProgressBar1.Value = xh
Next
Me.ToolStripProgressBar1.Maximum = Xzjl.Count - 1
For xh As Int32 = 0 To Xzjl.Count - 1
Me.TextBoxurl.Text = "www.1234.com/" & Xzjl.GetKey(xh)
Try
Dim Dc As New Uri("ftp://1234.com/" & Xzjl.GetKey(xh))
My.Computer.Network.DownloadFile(Dc, _
Xzjl.GetByIndex(xh), "1234", "1234", False, 500, True, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/失败.txt", Xzjl.GetKey(xh) & Chr(13) & Chr(10), False)
' Exit Sub
End Try
Me.ToolStripProgressBar1.Value = xh
Me.Label1下载数量.Text = "下载总数:" & Xzjs & " 剩余:" & Xzjs - xh
Next
Me.ToolStripProgressBar1.Visible = False
ToolStripStatusLabel备份.Text = "备份完成"
使用了第三方的控件:
nBitFTP.clsFTP 可以完全按照FTP的目录下载。
oFTP.Host = "www. 1234.com"
oFTP.UserName = "1234"
oFTP.Password = "1234"
Me.ListBox1.Items.Clear()
Dim wjj As New System.Collections.ArrayList
If oFTP.connect() = True Then '创建连接
If oFTP.GetDirectoryListing("*.*") = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." Then
wjj.Add(Wmc)
End If
Next
End If
End If
Dim Js As Int16 = 0
While wjj.Count <> Js
Js = wjj.Count
If oFTP.connect() = True Then '创建连接
For xh As Int32 = 0 To wjj.Count - 1
If oFTP.GetDirectoryListing(wjj(xh)) = True Then
For X As Int32 = 0 To oFTP.Directory.Count - 1
Dim Wmc As String = oFTP.Directory.Item(X + 1).FileName
If oFTP.Directory.Item(X + 1).Directory = True Then
If oFTP.Directory.Item(X + 1).Directory = True And Wmc <> "." And Wmc <> ".." _
And wjj.Contains(wjj(xh) & "/" & Wmc) = False Then
wjj.Add(wjj(xh) & "/" & Wmc)
End If
End If
Next
End If
Next
End If
End While
For xh As Int32 = 0 To wjj.Count - 1
Me.ListBox1.Items.Add(wjj(xh))
If IO.Directory.Exists(Me.TextBoxsave.Text & "/" & wjj(xh)) = False Then
IO.Directory.CreateDirectory(Me.TextBoxsave.Text & "/" & wjj(xh))
End If
Dgwj(wjj(xh))
Next
Me.ToolStripProgressBar1.Visible = True
Dim Xzjs As Int32 = 0
Me.ToolStripProgressBar1.Maximum = Me.DataGridVieFile.Rows.Count - 1
Dim Xzjl As New System.Collections.SortedList
For xh As Int32 = 0 To Me.DataGridVieFile.Rows.Count - 1
Dim Wmc As String = Me.DataGridVieFile.Rows(xh).Cells(0).Value
Dim Bdwj As String = Me.TextBoxsave.Text & "/" & Wmc
Dim Wjcd As Int32 = Me.DataGridVieFile.Rows(xh).Cells(2).Value
Dim Xgsj As Date = Me.DataGridVieFile.Rows(xh).Cells(3).Value
If IO.File.Exists(Bdwj) = False Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
Else
If New IO.FileInfo(Bdwj).Length < Wjcd Or New IO.FileInfo(Bdwj).LastWriteTime < Xgsj Then
Xzjs += 1
Me.Label1下载数量.Text = Xzjs
Xzjl.Add(Wmc, Bdwj)
End If
End If
Me.ToolStripProgressBar1.Value = xh
Next
Me.ToolStripProgressBar1.Maximum = Xzjl.Count - 1
For xh As Int32 = 0 To Xzjl.Count - 1
Me.TextBoxurl.Text = "www.1234.com/" & Xzjl.GetKey(xh)
Try
Dim Dc As New Uri("ftp://1234.com/" & Xzjl.GetKey(xh))
My.Computer.Network.DownloadFile(Dc, _
Xzjl.GetByIndex(xh), "1234", "1234", False, 500, True, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
My.Computer.FileSystem.WriteAllText(Application.StartupPath & "/失败.txt", Xzjl.GetKey(xh) & Chr(13) & Chr(10), False)
' Exit Sub
End Try
Me.ToolStripProgressBar1.Value = xh
Me.Label1下载数量.Text = "下载总数:" & Xzjs & " 剩余:" & Xzjs - xh
Next
Me.ToolStripProgressBar1.Visible = False
ToolStripStatusLabel备份.Text = "备份完成"
使用了第三方的控件:
nBitFTP.clsFTP 可以完全按照FTP的目录下载。
#5
http://www.west263.com/www/info/32993-1.htm
#6
用自带的FtpWebRequest 类试试,流程可以参考三楼说的,先得到一个列表,然后根据列表下载文件
以下是关于FtpWebRequest 类的MSDN参考
http://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest(VS.80).aspx
以下是关于FtpWebRequest 类的MSDN参考
http://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest(VS.80).aspx
#7
http://blog.csdn.net/Going1981/archive/2009/04/23/4103199.aspx
类里有异步下载的方法,下载进度changed事件、Completed事件都有,真是太好用了。
下面的代码可以将指定FTP的目录及下面所有子目录复制到本地,你自己加入下载的方法吧。
'先引用上面的类,或者直接Copy到项目里 (拿来主义 =。=|| )
Private Sub CreateFloders(ByVal sourcepath As String, ByVal savepath As String)
obj.GotoDirectory(sourcepath)
Dim dirlist As FileStruct() = obj.ListDirectories '获取目录列表
Dim dir As String = ""
If sourcepath.IndexOf("\") > 0 Then
dir = savepath & sourcepath.Substring(sourcepath.LastIndexOf("\"))
Else
dir = savepath & sourcepath
End If
System.IO.Directory.CreateDirectory(dir) '在本地创建目录
For i As Integer = 0 To dirlist.Length - 1
System.IO.Directory.CreateDirectory(dir & "\" & dirlist(i).Name)
obj.GotoDirectory(dirlist(i).Name)
Dim subdirlist As FileStruct() = obj.ListDirectories '获取子目录
If subdirlist.Length > 0 Then
CreateFloders(sourcepath & "\" & dirlist(i).Name, dir) '如果有子目录,递归
obj.GotoDirectory(sourcepath) '返回上级目录
End If
Next
End Sub
调用方法:
Private WithEvents obj As New clsFTP
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
obj.Uri = New Uri("ftp:\\124.193.***.***:**")
obj.UserName = "myuser"
obj.Password = "************"
CreateFloders(".\test", "D:\") '将FTP主目录\test 复制到本地D:\下
'obj.DownloadFileAsync("bsmain_runtime.log", "C:\", "1.txt")
'AddHandler obj.DownloadDataCompleted, AddressOf test
End Sub
#8
我试试。
#9
#10
学习
#11
帮顶
#12
学习啊