English 中文(简体)
I need to pull large backup files from my clients servers to my server every month
原标题:

I have clients out there running an SQL Server Express 2005 and each of these needs a backup each month and that backup needs to be moved to our server in case they lose their backup. Our software automatically backs up the database each month but we have to manually go in and copy it across. Is there any way to automate the copying of files up to 800 megs from their machine to ours each month perhaps using FTP? Also, if using FTP it has to support resume in case we lose the connection three querters through which happens quite often. I would like to write this functionality into our VB.net application that only requires the .net framework and not use any third party controls.

问题回答

I think this is where you d be better off if you used something like RSync rather than a home-grown solution.

Another alternative would be to use a program like SyncBack, that supports syncronization across FTP, can be scheduled to run daily/weekly/monthly and has worked for me to do what you re talking about, for years. I m not sure about Resuming an FTP transfer - but it does a great job of backing things up across FTP.

It s certainly doable with either the WebClient classes, or (Ftp)WebRequest/WebResponse series of classes - and I can give you some sample code if required - but unless you have some specific business case for rolling your own something like RSync may be the better choice.

EDIT;

The WebClient route is the simplest, but it doesn t give you much control;

Imports System.Net
...
Dim Client As New WebClient
Client.DownloadFile("ftp://ftp.example.com/Database.bak", "D:BackupsDatabase.bak")

If you want a bit more control, and to manage FTP resumes then something like this will do the trick;

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

This assumes you re transferring from FTP -> local. Username/password can be supplied as in the SourcePath as so; ftp://username:password@ftp.mysite.co.uk

Hope this helps.





相关问题
Backing up my database is taking too long

On a windows mobile unit, the software I m working on relies on a sdf file as it s database. The platform that the software is targeted towards is "less than optimal" and hard resets every once and a ...

Cognos LAE Backup Automation (Batch File?)

Within Cognos 7.4 security.. one would create an LAE file to export all their users... directions here... http://www.cognos-install.co.uk/articles/backups/access_manager_export_to_lae.asp Now you ...

backup SQL Server 2005 database without data

I have one stored procedure to backup the database. It will backup metadata as well as data. Is there any option to back up the database with out data. ie, back up only the schema (Empty tables). I ...

SQL Server 2008 Auto Backup

We want to have our test servers databases updated from our production server databases on a nightly basis to ensure we re developing on the most recent data. We, however, want to ensure that any fn, ...

mysql dump stops when a row is updated

When i try to get a dump of a mysql database, the dump stops when a row in it is updated. How can i prevent that? I already tried following options with no result: -f (forces continu even when error)...

热门标签