Link to home
Start Free TrialLog in
Avatar of LeighWardle
LeighWardleFlag for Australia

asked on

Access 2016 VBA code to upload a file to a FTP server

Hi Experts,

I'm looking for code or a package that can be called from Access 2016 VBA code to upload a file to a FTP server.

Thanks,

Regards,
Leigh
Avatar of LeighWardle
LeighWardle
Flag of Australia image

ASKER

One other requirement is that the VBA code must be able to create a subfolder on the FTP server.
Avatar of Michael Pfister
https://dbwiki.net/wiki/VBA_Tipp:_Datei-Download_und_-Upload_(FTP)
Sample VBA source for using wininet.dll for FTP.
CreateDirectory is missing
 
Private Declare Function FtpCreateDirectory Lib "wininet.dll" _
   Alias "FtpCreateDirectoryA" ( _
   ByVal hConnect As Long, _
   ByVal lpszDirectory As String) As Bool
 

Open in new window

Haven't tested the code ...
HTH
Well i just tested this:
1 Download from here  the beta TransferLibrary
2. extract from the zip the .dll and place it in SysWOW64
3. Open your Access Application and reference the .dll -->Tools -->References --> Browse find the above .dll
4  the code provided originally needs a bit of tweaking ....this below works
Public Function FtpUpload()

Dim objFTP As InternetTransferLib.FTP
Dim ftpURL As String
Dim ftpUser As String
Dim ftpPassword As String
Dim ftpDirectory As String
Dim sourceFile As String
Dim destinationFileName As String
ftpURL = "YOUR FTP"
ftpUser = "FTP USER NAME"
ftpPassword = "FTP PASSWORD"
ftpDirectory = " THE NAME OF THE DIRECTORY"
sourceFile = "Complete Path of the File" 'e.g C:\Temp\Somefile.txt
destinationFileName = "The Name of the File on the FTP " 'e.g Somefile.txt
  Set objFTP = New InternetTransferLib.FTP
  With objFTP
  .Connect ftpURL, True, ftpUser, ftpPassword
  .CreateDirectory ftpDirectory
  .ChangeDirectory ftpDirectory
  .Upload ITL_INTERNET_FLAG_TRANSFER_BINARY, sourceFile, destinationFileName, True
  End With

End Function

Open in new window

Hi John,

Your code looks promising!

Will it create a subfolder on the FTP server, if it does not already exist?

Regards,
Leigh
The code does exactly what you need ...creating a non existed directory...tested and working fine..
Be aware that the other technique of doing FTP is simply to execute a batch file that you write out with Shell() against a FTP client you have installed.

With this, you can use a number of FTP clients depending on your need.  For example, I have one client that makes use of the Microsoft FTP client, one from MoveIT, and WinSCP.

Jim.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks John - all working in production mode.

Regards,
Leigh