Display-file-transfer-progress-in-SFTP-protocol - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Display file transfer progress in SFTP protocol
VB code
Dim WithEvents wodSFTP1 As wodSFTPCom
Private Sub Form_Load()
    Set wodSFTP1 = New wodSFTPCom
    
    'Authenticate with server using hostname, login, password.
    wodSFTP1.HostName = "your_hostname"
    wodSFTP1.Login = "your_login"
    wodSFTP1.Password = "your_password"
    wodSFTP1.Connect
End Sub

'Connected Event is triggered after connection with server is established.
Private Sub wodSFTP1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
    If ErrorCode = 0 Then
       'In this example we will upload some file to server. Same procedure is for downloading file.
'When downloading file GetFile Method should be used.
wodSFTP1.PutFile "c:\somefile.exe", "/home/somefolder" Else 'Receive connection error here. If there were any. MsgBox "Connected Error: " & ErrorText End If End Sub 'Progress Event is triggered during file transfer. 'Position argument inside Progress Event is used to show current transfer position. 'Total argument shows total number of bytes that should be transferred. Private Sub wodSFTP1_Progress(ByVal Position As Long, ByVal Total As Long) Dim result As Double 'We will monitor file transfer progress in percentage. result = (Position / Total) * 100 'Result of file transfer progress will be displayed only using two decimals using this code. Debug.Print Format(result, "0.00") & " %" End Sub
VB.NET code
Dim WithEvents wodSFTP1 As WeOnlyDo.Client.SFTP
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodSFTP1 = New WeOnlyDo.Client.SFTP

    'Authenticate with server using hostname, login, password.
    wodSFTP1.Hostname = "your_hostname"
    wodSFTP1.Login = "your_login"
    wodSFTP1.Password = "your_password"
    wodSFTP1.Connect()
End Sub

'Connected Event is triggered after connection with server is established.
Private Sub wodSFTP1_ConnectedEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SFTP.ConnectedArgs) Handles wodSFTP1.ConnectedEvent
    If (Args.Error Is Nothing) Then
        'In this example we will upload some file to server. Same procedure is for downloading file.
'When downloading file GetFile Method should be used.
wodSFTP1.PutFile("c:\somefile.exe", "/home/somefolder") Else 'Receive connection error here. If there were any. MsgBox("Connected Error: " + Args.Error.Message) End If End Sub 'Progress Event is triggered during file transfer. 'Position argument inside Progress Event is used to show current transfer position. 'Length argument shows total number of bytes that should be transferred. Private Sub wodSFTP1_ProgressEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Client.SFTP.ProgressArgs) Handles wodSFTP1.ProgressEvent Dim result As Double 'We will monitor file transfer progress in percentage. result = (Args.Position / Args.Length) * 100 'Result of file transfer progress will be displayed only using two decimals using this code. Console.WriteLine(Math.Round(result, 2) & " %") End Sub
C# code
WeOnlyDo.Client.SFTP wodSFTP1;
private void Form1_Load(object sender, EventArgs e)
{
    wodSFTP1 = new WeOnlyDo.Client.SFTP();
    wodSFTP1.ConnectedEvent += new WeOnlyDo.Client.SFTP.ConnectedDelegate(wodSFTP1_ConnectedEvent);
    wodSFTP1.ProgressEvent += new WeOnlyDo.Client.SFTP.ProgressDelegate(wodSFTP1_ProgressEvent);

    //Authenticate with server using hostname, login, password.
    wodSFTP1.Hostname = "your_hostname";
    wodSFTP1.Login = "your_login";
    wodSFTP1.Password = "your_password";
    wodSFTP1.Connect();
}

//Connected Event is triggered after connection with server is established.
void wodSFTP1_ConnectedEvent(object Sender, WeOnlyDo.Client.SFTP.ConnectedArgs Args)
{
    if (Args.Error == null)
    {
        //In this example we will upload some file to server. Same procedure is for downloading file.
//When downloading file GetFile Method should be used.
wodSFTP1.PutFile("c:\\somefile.exe", "/home/somefolder"); } else //Receive connection error here. If there were any. MessageBox.Show("Connected Error: " + Args.Error.Message); } //Progress Event is triggered during file transfer. //Position argument inside Progress Event is used to show current transfer position. //Length argument shows total number of bytes that should be transferred. void wodSFTP1_ProgressEvent(object Sender, WeOnlyDo.Client.SFTP.ProgressArgs Args) { double result; //We will monitor file transfer progress in percentage. result= ((double)Args.Position / Args.Length)*100; //Result of file transfer progress will be displayed only using two decimals using this code. Console.WriteLine(Math.Round(result, 2) + " %"); }