Freelance Project Requests Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net

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


Download von Files

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


Upload von files

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


Rename von Files

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


List Verzeichnisse in Remote Verzeichnis

ListDirectory Lists remote directory.





Vba Code Example

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

' Shell variant

' WinSCP console interface .NET wrapper


Private Sub fl_Download_SFTP()

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


    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          '

        .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




    '    ' 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


    End If


    ' Disconnect, clean up



    ' Restore default error handling

    On Error GoTo 0

    '--</ Abschluss >--

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

End Sub




Contact for Jobs, Project Requests: