File Upload Using SFTP Using VBA

My goal is to download, not download the file from the SFTP server, and I'm trying to adapt the code from another question on this site to do this (I pasted the code below for your convenience).

I downloaded PSFTP from Putty. PSFTP closes when I try to connect using the following command line:

open username:password@server.com.port:1111 

I have three questions:

  • Is there something wrong with my command line? If not, what is the problem?

  • As far as I know, SFTP usually uses get / put commands, but I don’t see the put command in the code below, so I don’t understand where I have to get the get command to load instead of loading it (which is what the code should do below) .

  • Is it right that pRemotePath is the location of the file on the SFTP server, and pFile is the location where I want to upload the file?

A simple explanation would be greatly appreciated.

Public Sub SftpGet()

    Const cstrSftp As String = """C:\Users\Ron\UtilityTools\psftp.exe"""
    Dim strCommand As String
    Dim pUser As String
    Dim pPass As String
    Dim pHost As String
    Dim pFile As String
    Dim pRemotePath As String

    pUser = "uid"
    pPass = "PW"
    pHost = "dns"
    pFile = "C:\Users\Ron\activity.txt" 
    pRemotePath = "Z:/activity.log"

    strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
        " " & pFile & " " & pHost & ":" & pRemotePath
    Debug.Print strCommand
    Shell strCommand, 1 ' vbNormalFocus '
End Sub
+3
source share
1 answer

I think you should start with a Windows command line session. Define the details of your command line there, as I suggested in response to a similar question: Download SFTP using VBA . Once you have the command line running there, executing the same command from VBA will be very simple.

Putty psftp.exe, pscp.exe, , psftp.exe. , Putty, , PSFTP (pscp.exe) SSH-2 --- SSH-1, PSFTP .

, Putty .

+1

All Articles