#

Access: Download sftp Files

 

 

Referenz zu den Code-Beispielen für winSCP SFTP Programmierung in Office vba

 

Sobald das Session Objekt erstellt ist kann man mit diesen Files downloaden und uploaden

SFTP Session Objekt

http://winscp.net/eng/docs/library_session

 

Download von Files

GetFiles       Downloads files. one or more files from remote directory to local directory.

http://winscp.net/eng/docs/library_session_getfiles

 

Upload von files

PutFiles        Uploads files, Uploads one or more files from local directory to remote directory.

http://winscp.net/eng/docs/library_session_putfiles

 

Rename von Files

http://winscp.net/eng/docs/library_session_movefile

MoveFile      Moves remote file to another remote directory and/or renames remote file.

 

List Verzeichnisse in Remote Verzeichnis

ListDirectory Lists remote directory.

http://winscp.net/eng/docs/library_session_listdirectory

 

 

 

 

Vba Code Example

'==========================< Functions >===========================

' Shell variant

' WinSCP console interface .NET wrapper

' http://winscp.net/eng/docs/library_vb

Private Sub fl_Download_SFTP()

    '--------< fl_Download_SFTP() >--------

    'sftp-Session

    Dim mySession As New session

 

    ' Enable custom error handling

    On Error Resume Next

 

    '< get FileExplorer Functions >

    ' Setup session options

    Dim mySessionOptions As New SessionOptions

    With mySessionOptions

        .Protocol = Protocol_Sftp

        .HostName = tbxFolder_Remote_FTP.Value          'secure.domain.de

        .UserName = tbxUser.Value                       'user

        .Password = tbxPassword.Value                   'password_abc123

        .SshHostKeyFingerprint = tbxSSHKey.Value        '"ssh-rsa 2048 1a:2b:3c:4d:5d:6e:7f:8g:1a:2b:3c:4d:5d:6e:7f:8g"

    End With

    '</ get FileExplorer Functions >

 

    ' Connect

    mySession.Open mySessionOptions

 

    Dim directoryInfo As RemoteDirectoryInfo

    directoryInfo = mySession.ListDirectory("/home/SP")

 

    Dim varFile

    For Each varFile In directoryInfo.Files

        Dim sFile As String

        sFile = varFile.Name

        addLog sFile

 

        If sFilename Like "*.csv" Then

 

        End If

 

    Next

 

    '    ' Upload files

    '    Dim myTransferOptions As New TransferOptions

    '    myTransferOptions.TransferMode = TransferMode_Binary

    '

    '    Dim transferResult As TransferOperationResult

    '    Set transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions)

    '

    '    ' Throw on any error

    '    transferResult.Check

    '

    '    ' Display results

    '    Dim transfer As TransferEventArgs

    '    For Each transfer In transferResult.Transfers

    '        MsgBox "Upload of " & transfer.FileName & " succeeded"

    '    Next

 

 

    '--< Abschluss >--

    ' Query for errors

    If Err.Number <> 0 Then

        MsgBox "Error: " & Err.Description

 

        ' Clear the error

        Err.Clear()

    End If

 

    ' Disconnect, clean up

    mySession.Dispose()

 

    ' Restore default error handling

    On Error GoTo 0

    '--</ Abschluss >--

    '--------</ fl_Download_SFTP() >--------

End Sub

 

Mobile

.

0123movie.net