1

Dode below doesn't return an error, or "success" or "fail" but it also doesn't work - information in the sub TestUpload that is CAPITALIZED is the only info that i changed to make this post - everything else is legit - thanks in advance.

Option Compare Database

Private Const FTP_TRANSFER_TYPE_UNKNOWN     As Long = 0
Private Const INTERNET_FLAG_RELOAD          As Long = &H80000000

Private Declare Function InternetOpenA Lib "wininet.dll" ( _
    ByVal sAgent As String, _
    ByVal lAccessType As Long, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As Long) As Long

Private Declare Function InternetConnectA Lib "wininet.dll" ( _
    ByVal hInternetSession As Long, _
    ByVal sServerName As String, _
    ByVal nServerPort As Long, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As Long, _
    ByVal lFlags As Long, _
    ByVal lcontext As Long) As Long

Private Declare Function FtpPutFileA _
   Lib "wininet.dll" _
 _
       (ByVal hFtpSession As Long, _
        ByVal lpszLocalFile As String, _
        ByVal lpszRemoteFile As String, _
        ByVal dwFlags As Long, _
        ByVal dwContext As Long) As Boolean

Private Declare Function InternetCloseHandle Lib "wininet" ( _
    ByVal hInet As Long) As Long

Sub FtpUpload(ByVal strLocalFile As String, ByVal strRemoteFile As String, ByVal strHost As String, ByVal lngPort As Long, ByVal strUser As String, ByVal strPass As String)
    Dim hOpen   As Long
    Dim hConn   As Long

    hOpen = InternetOpenA("FTPGET", 1, vbNullString, vbNullString, 1)
    hConn = InternetConnectA(hOpen, strHost, lngPort, strUser, strPass, 1, 0, 2)

    If FtpPutFileA(hConn, strLocalFile, strRemoteFile, FTP_TRANSFER_TYPE_UNKNOWN Or INTERNET_FLAG_RELOAD, 0) Then
        Debug.Print "Success"
    Else
        Debug.Print "Fail"
    End If

    'Close connections
    InternetCloseHandle hConn
    InternetCloseHandle hOpen

End Sub


Sub TestUpload()
  FtpUpload "C:\Users\FOLDER\UPLOAD FILE.csv", "/<root>/SFTPSITE FOLDER NAME/admin", _
            "IP.ADDRESS.OF.SFTPSITE", "22", "SIGNIN@sftp.DOMAIN.com", "PASSWORD"
End Sub
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
bobby
  • 15
  • 1
  • 7
  • Have you step debugged? – June7 Sep 01 '18 at 19:17
  • 2
    You mention "SFTP" in your subject. Does that mean it is secured by SSH or some other encrypted protocol? If so you'll probably need to use an external library - I don't think the WinINet functions support them. – Comintern Sep 01 '18 at 19:21
  • Definitely, WinINet do not support SFTP. - Consider: [Using VBA to run WinSCP script](https://stackoverflow.com/q/37280733/850848). – Martin Prikryl Sep 01 '18 at 19:59
  • I'd assume op is actually trying to use SFTP (port in question is 22). I'm closing as too broad since the solution will likely require third party software or be very complex – Erik A Sep 01 '18 at 20:03
  • ok thx for the feedback - i'll try the above. – bobby Sep 01 '18 at 23:16
  • If your time isn't for free, consider https://www.chilkatsoft.com/refdoc/xChilkatSFtpRef.html // https://www.example-code.com/vbscript/sftp.asp – Andre Sep 04 '18 at 07:39

1 Answers1

0

WinINet functions do not support SFTP protocol (FTP protocol is completely different).

There's no native support for SFTP in VBA nor in Windows API. You have to use a 3rd party library or software.

See these questions for some examples:

(I'm the author of WinSCP)

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • sorry - i thought the above wouldnt work because i confused FTP with SFTP, so i sought another solution. the reality is, thanks to this website i'm actually able to do a lot of the things i need to, but i do not know nearly enough about the process to have a smart chat on it – bobby Sep 07 '18 at 19:04
  • im still working on the other solution, but i will go ahead and close out this question - if you could be so kind as to let me know how i do that. thx. – bobby Sep 07 '18 at 20:00