login about faq

Hello

I am uploading a file using sftp. I have a progress bar and I am trying to get the progress to update.

I have enabled events and I set the callback event but it does not do anything

I have this at the top:

Dim WithEvents sftp As New Chilkat.SFtp

This is the OnPercentDone sub:

Private Sub sftp_OnPercentDone(sender As Object, args As Chilkat.PercentDoneEventArgs) Handles sftp.OnPercentDone
    pbCopyProgress.Value = args.PercentDone
    UpdateLogWindow("Percent Done = " + args.PercentDone.ToString)

End Sub

when the upload starts nothing happens to the progress bar. What am I doing wrong?

asked Mar 20 '14 at 14:20

kevindcs's gravatar image

kevindcs
11556


I found no problem. Here's the complete sample I used for testing:

Public Class Form1

Dim WithEvents m_sftp As Chilkat.SFtp

Private Sub m_sftp_OnPercentDone(sender As Object, args As Chilkat.PercentDoneEventArgs) Handles m_sftp.OnPercentDone
    ProgressBar1.Value = args.PercentDone
End Sub

Private Sub UploadWithProgressToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UploadWithProgressToolStripMenuItem.Click
    m_sftp = New Chilkat.SFtp()

    '  Any string automatically begins a fully-functional 30-day trial.
    Dim success As Boolean
    success = m_sftp.UnlockComponent("test")
    If (success <> True) Then

        TextBox1.Text = m_sftp.LastErrorText
        Exit Sub
    End If

    '  Set some timeouts, in milliseconds:
    m_sftp.ConnectTimeoutMs = 15000
    m_sftp.IdleTimeoutMs = 15000

    '  Connect to the SSH server.
    '  The standard SSH port = 22
    '  The hostname may be a hostname or IP address.
    Dim port As Long
    Dim hostname As String
    hostname = "192.168.1.127"
    port = 22
    success = m_sftp.Connect(hostname, port)
    If (success <> True) Then
        TextBox1.Text = m_sftp.LastErrorText
        Exit Sub
    End If

    '  Authenticate with the SSH server.  Chilkat SFTP supports
    '  both password-based authenication as well as public-key
    '  authentication.  This example uses password authenication.
    success = m_sftp.AuthenticatePw("chilkat", "xxx")
    If (success <> True) Then
        TextBox1.Text = m_sftp.LastErrorText
        Exit Sub
    End If

    '  After authenticating, the SFTP subsystem must be initialized:
    success = m_sftp.InitializeSftp()
    If (success <> True) Then
        TextBox1.Text = m_sftp.LastErrorText
        Exit Sub
    End If

    '  Upload from the local file to the SSH server.
    '  Important -- the remote filepath is the 1st argument,
    '  the local filepath is the 2nd argument;
    Dim remoteFilePath As String
    remoteFilePath = "hamlet.xml"
    Dim localFilePath As String
    localFilePath = "c:/aaworkarea/hamlet.xml"

    success = m_sftp.UploadFileByName(remoteFilePath, localFilePath)
    If (success <> True) Then
        TextBox1.Text = m_sftp.LastErrorText
        Exit Sub
    End If

    MsgBox("Success.")
End Sub

End Class

link

answered Mar 20 '14 at 16:38

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

I am using a background worker, could that have something to do with it?

link

answered Mar 20 '14 at 16:43

kevindcs's gravatar image

kevindcs
11556

Most certainly. Research the topic of accessing/updating controls on the main thread from a background worker thread. For example: http://stackoverflow.com/questions/6937300/vb-net-winforms-how-to-access-objects-of-main-thread-from-backgroundworkers-t

link

answered Mar 20 '14 at 17:02

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

I figured it out. I was declaring the sftp inside the sub and that was overwriting the sftp that had the Dim WithEvents

link

answered Mar 20 '14 at 17:11

kevindcs's gravatar image

kevindcs
11556

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×200
×50
×43
×22
×10

Asked: Mar 20 '14 at 14:20

Seen: 1,754 times

Last updated: Mar 20 '14 at 17:11

powered by OSQA