Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Function FTPDownloadFile(ByVal HostName As String, _
ByVal UserName As String, _
ByVal Password As String, _
ByVal LocalFileName As String, _
ByVal RemoteFileName As String, _
ByVal sDir As String, _
ByVal sMode As String) As Boolean
' Declare variables
Dim hConnection, hOpen ' Used For Handles
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
'check for existence of destination file
If fso.FileExists(LocalFileName) Then
'delete it if found
VBA.Kill LocalFileName
End If
' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
' Connect to FTP
hConnection = InternetConnect(hOpen, HostName, & _ INTERNET_DEFAULT_FTP_PORT, UserName, Password, & _ INTERNET_SERVICE_FTP, IIf(PassiveConnection, & _ INTERNET_FLAG_PASSIVE, 0), 0)
' Change Directory
Call FtpSetCurrentDirectory(hConnection, sDir)
' Set Download Flag to True
FTPDownloadFile = True
' Download File
If FTPGetFile(hConnection, RemoteFileName, & _
LocalFileName, False, 1, 0, 1) = False Then
MsgBox "Download - Failed At FTPGetFile!"
FTPDownloadFile = False
End If
'ensure file is not saved as read-only
SetAttr LocalFileName, vbNormal + vbArchive
' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)
End Function
Function FTPUploadFile(ByVal HostName As String, _
ByVal UserName As String, _
ByVal Password As String, _
ByVal LocalFileName As String, _
ByVal RemoteFileName As String, _
ByVal sDir As String, _
ByVal sMode As String) As Boolean
'If this function is not working,
'try playing with Flags and Context
'(2nd and 3rd parameters in FTPPutFile)
' Declare variables
Dim hConnection, hOpen ' Used For Handles
' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
' Connect to FTP
hConnection = InternetConnect(hOpen, HostName, & _ INTERNET_DEFAULT_FTP_PORT, UserName, Password, & _ INTERNET_SERVICE_FTP, IIf(PassiveConnection, & _ INTERNET_FLAG_PASSIVE, 0), 0)
' Change Directory
Call FtpSetCurrentDirectory(hConnection, sDir)
' Set Upload Flag to True
FTPUploadFile = True
' Download File
If FtpPutFile(hConnection, LocalFileName, & _
RemoteFileName, 0, 1) = False Then
MsgBox "Download - Failed At FTPPutFile!"
FTPUploadFile = False
End If
' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)
End Function