Hi, I wonder if anyone can assist me please.
The below code works well in my Access Database at work, but somehow not in the same database from home.
I modified the code to allow 64bit systems (computer at work), whereas one at home is 32 bit.
The file to upload's directory is changed from my work computer to my home computer.
I have stripped the username, password and user directory from the code below
(Code thanks to https://analystcave.com/vba-downloading-files-from-ftp-using-vba/)
The below code works well in my Access Database at work, but somehow not in the same database from home.
I modified the code to allow 64bit systems (computer at work), whereas one at home is 32 bit.
The file to upload's directory is changed from my work computer to my home computer.
I have stripped the username, password and user directory from the code below
(Code thanks to https://analystcave.com/vba-downloading-files-from-ftp-using-vba/)
Code:
Option Compare Database
Private Const FTP_TRANSFER_TYPE_UNKNOWN As Long = 0
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Declare PtrSafe 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 PtrSafe 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 PtrSafe 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 PtrSafe 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 "H:\My Documents\AccessDatabases\Exports\Setup.pdf", "/xxxx.com/public_html/Reports/Setup.pdf", _
"userwebsite", 21, "username", "userpassword"
End Sub
Last edited: