Differences
This shows you the differences between the selected revisions of the page.
| 2012-03-26 | 2012-04-03 | ||
| vb.net signature (martin) | vbnet example (martin) | ||
| Line 84: | Line 84: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | |||
| + | ==== [[vbnet]] VB.NET Example ==== | ||
| + | <code vbnet> | ||
| + | Imports System | ||
| + | Imports WinSCP | ||
| + | |||
| + | Friend Class Example | ||
| + | |||
| + | Public Shared Function Main() As Integer | ||
| + | |||
| + | Try | ||
| + | ' Setup session options | ||
| + | Dim sessionOptions As New SessionOptions; | ||
| + | With sessionOptions | ||
| + | .Protocol = Protocol.Sftp | ||
| + | .HostName = "example.com" | ||
| + | .UserName = "user" | ||
| + | .Password = "mypassword" | ||
| + | .SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
| + | End With | ||
| + | |||
| + | Using session As Session = New Session | ||
| + | ' Connect | ||
| + | session.Open(sessionOptions) | ||
| + | |||
| + | ' Execute mysqldump on the server to dump all MySQL databases and compress the results | ||
| + | Const dbUsername As String = "USERNAME" | ||
| + | Const dbPassword As String = "PASSWORD" | ||
| + | Const tempFilePath As String = "/tmp/all_databases.gz" | ||
| + | |||
| + | ' Execute mysqldump on the server to dump all MySQL databases and compress the results | ||
| + | Dim dumpCommand As String = _ | ||
| + | String.Format("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}", _ | ||
| + | dbUsername, dbPassword, tempFilePath) | ||
| + | session.ExecuteCommand(dumpCommand) | ||
| + | |||
| + | ' Download the database dump | ||
| + | session.GetFiles(tempFilePath, "D:\dbbackup\").Check | ||
| + | End Using | ||
| + | |||
| + | Return 0 | ||
| + | Catch e As Exception | ||
| + | Console.WriteLine("Error: {0}", e) | ||
| + | Return 1 | ||
| + | End Try | ||
| + | |||
| + | End Function | ||
| + | |||
| + | End Class | ||
| </code> | </code> | ||