人人人人人人人人人人人人

SFTP Using Chilkat Active component

https://www.example-code.com/vb6/sftp_uploadBandwidthThrottle.asp

Private Sub Command1_Click()
' Important: It is helpful to send the contents of the
' sftp.LastErrorText property when requesting support.

' Dim sftp As New ChilkatSFtp

'  Any string automatically begins a fully-functional 30-day trial.
Dim success As Long
success = sftp.UnlockComponent("Anything for 30-day trial")

If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    Exit Sub
End If

'  Set some timeouts, in milliseconds:
sftp.ConnectTimeoutMs = 15000
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 = "www.my-ssh-server.com"
hostname = "127.0.0.1"
port = 22
success = sftp.Connect(hostname, port)
If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    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 = sftp.AuthenticatePw("myLogin", "myPassword")
 success = sftp.AuthenticatePw("wgscd1", "111111")


If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    Exit Sub
End If

'  After authenticating, the SFTP subsystem must be initialized:
success = sftp.InitializeSftp()
If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    Exit Sub
End If

'  Limit the transfer rate (bandwidth throttle) to 64K per second.
sftp.BandwidthThrottleUp = 65536

'  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:/temp/hamlet.xml"
success = sftp.UploadFileByName(remoteFilePath, localFilePath)
If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    Exit Sub
End If

Text1.Text = Text1.Text & "Success." & vbCrLf


  success = sftp.DownloadFileByName("TrackMM5--.exe", "c:/temp/TrackMM5--.exe")

If (success <> 1) Then
    Text1.Text = Text1.Text & sftp.LastErrorText & vbCrLf
    Exit Sub
End If
 Text1.Text = Text1.Text & "Download File Success." & vbCrLf

End Sub

Private Sub sftp_PercentDone(ByVal percent As Long, abort As Long)
Caption = Caption & "," & percent

End Sub

posted @ 2016-09-22 11:17  wgscd  阅读(511)  评论(0编辑  收藏  举报