我有运行 SQL Server Express 2005 的客户,每个月都需要备份,并且需要将备份移动到我们的服务器,以防他们丢失备份。我们的软件每个月都会自动备份数据库,但我们必须手动进入并复制它。有什么方法可以自动将文件从他们的机器复制到我们的机器上,最多 800 兆,也许是使用 FTP?此外,如果使用 FTP,它必须支持恢复,以防我们失去经常发生的三个连接。我想将此功能写入我们的 VB.net 应用程序,该应用程序只需要 .net 框架,不使用任何第三方控件。
问问题
228 次
3 回答
2
我认为如果你使用RSync之类的东西而不是本土解决方案,你会在这方面做得更好。
于 2010-02-19T12:05:49.637 回答
0
另一种选择是使用像 SyncBack 这样的程序,它支持跨 FTP 同步,可以安排每天/每周/每月运行,并且多年来一直为我做你所说的事情。我不确定恢复 FTP 传输 - 但它在跨 FTP 备份方面做得很好。
于 2010-02-19T12:20:25.723 回答
0
它当然可以使用 WebClient 类或 (Ftp)WebRequest/WebResponse 系列类 - 如果需要,我可以给你一些示例代码 - 但除非你有一些特定的商业案例来滚动你自己的东西,比如 RSync 可能会更好选择。
编辑;
WebClient 路由是最简单的,但它并没有给您太多控制;
Imports System.Net
...
Dim Client As New WebClient
Client.DownloadFile("ftp://ftp.example.com/Database.bak", "D:\Backups\Database.bak")
如果你想要更多的控制,并管理 FTP 恢复,那么这样的事情就可以了;
Public Sub TransferFile(ByVal SourcePath As String, ByVal DestinationPath As String)
Dim SourceRequest As FtpWebRequest
Dim Buffer(4095) As Byte
Dim BytesRead As Integer
' Assumes source is on FTP server...
SourceRequest = DirectCast(WebRequest.Create(SourcePath), FtpWebRequest)
SourceRequest.Method = WebRequestMethods.Ftp.DownloadFile
' If we already have a local file, then resume from the end of it...
SourceRequest.ContentOffset = If(File.Exists(DestinationPath), New FileInfo(DestinationPath).Length, 0)
' Assume destination file is local/UNC file. FileMode.Append will create a new file if one doesn't exist.
Using DestinationFile As New FileStream(DestinationPath, FileMode.Append, FileAccess.Write, FileShare.None)
Using SourceResponse As WebResponse = SourceRequest.GetResponse()
Using SourceStream As Stream = SourceResponse.GetResponseStream()
Do
BytesRead = SourceStream.Read(Buffer, 0, Buffer.Length)
DestinationFile.Write(Buffer, 0, BytesRead)
' Calculate speed, progress, show to user/log, etc...
Loop While BytesRead > 0
End Using
End Using
End Using
End Sub
这假设您正在从 FTP -> 本地传输。用户名/密码可以像在 SourcePath 中一样提供;ftp://username:password@ftp.mysite.co.uk
希望这可以帮助。
于 2010-02-19T12:13:37.643 回答