master
xieguigang 7 years ago
parent 82efde73f2
commit dcecd5b9c2

@ -1,9 +1,104 @@
Imports Microsoft.VisualBasic.CommandLine.InteropService
Imports System.Text
Imports Microsoft.VisualBasic.CommandLine.InteropService
''' <summary>
''' aspera cli
''' </summary>
Public Class Aspera : Inherits InteropService
Dim maxSpeed$
Dim minSpeed$
ReadOnly server$
Public Property AdaptiveRate As Boolean
Public Property Encryption As Boolean
''' <summary>
''' ``&lt;username>@server_name``
''' </summary>
''' <param name="server">``&lt;username>@server_name``</param>
''' <param name="bin"></param>
Sub New(server$, Optional bin$ = "ascp")
Call MyBase.New(bin)
End Sub
''' <summary>
''' MB
''' </summary>
''' <param name="min%"></param>
''' <param name="max%"></param>
''' <returns></returns>
Public Function Speed(Optional min% = -1, Optional max% = -1) As Aspera
If min > 0 Then
minSpeed = min & "M"
Else
minSpeed = Nothing
End If
If max > 0 Then
maxSpeed = max & "M"
Else
maxSpeed = Nothing
End If
Return Me
End Function
''' <summary>
''' CLI for file transfer from ``a => b``
''' </summary>
''' <param name="a$"></param>
''' <param name="b$"></param>
''' <returns></returns>
''' <remarks>
''' + l - Allows for the user to set a maximum download speed that aspera should attempt to stay
''' at or below for the duration of the transfer. A speed in Megabits must be provided
''' with this flag.
''' + m - Allows for the user to set a minimum download sped that aspera should attempt to stay
''' at Or above for the duration of the transfer. A speed in Megabits must be provided with
''' this flag.
''' + Q - Turns adaptive rate on. Adaptive rate controls the speed of aspera with a goal of Not
''' dominating the bandwidth available. Very useful on busy networks that may have other
''' transfers ongoing.
''' + T - Turns encryption off. Turning encryption off will allow for a maximum throughput transfer
''' but should Not be provided if data being uploaded Is sensitive.
''' </remarks>
Private Function getCLI(a$, b$) As String
Dim cli As New StringBuilder
If Not maxSpeed.StringEmpty Then
Call cli.AppendLine($"-l {maxSpeed}")
End If
If Not minSpeed.StringEmpty Then
Call cli.AppendLine($"-m {minSpeed}")
End If
If AdaptiveRate Then
Call cli.AppendLine("-Q")
End If
If Not Encryption Then
Call cli.AppendLine("-T")
End If
Return cli.ToString
End Function
''' <summary>
'''
''' </summary>
''' <param name="local"></param>
''' <param name="remote"></param>
''' <returns></returns>
Public Function Upload(local$, remote$) As String
Return MyBase.RunProgram(getCLI(local, server & remote)).Run
End Function
''' <summary>
'''
''' </summary>
''' <param name="remote"></param>
''' <param name="local"></param>
''' <returns></returns>
Public Function Download(remote$, local$) As String
Return MyBase.RunProgram(getCLI(server & remote, local)).Run
End Function
End Class

Loading…
Cancel
Save