473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Automatically download spreadsheets, check updates from ftp site

I currently have code that brings up a form where the user can see a list of
spreadsheets on my ftp site, select one and then download and import the
spreadsheet into a table.

All of this processing is initiated by the user.

I'm thinking about automating some or all of this. My questions is: how do I
best determine when there is an update to a table in my Access Application
that is available on my ftp site?

I guess I could just have a table in my app that holds the name of
spreadsheets that have been downloaded. Then when there is an update, the
new spreadsheet name would be greater than the old spreadsheet name and that
would trigger the processing to at least notify the user that updates are
available.

However, there are a number of tables that need to be updated. I' m not sure
how to keep the code from comparing the wrong spreadsheets. In other words,
instead of just comparing SpreadsheetTableA update with SpreadsheetTableA
previous download, it may get confused and now compare SpreadsheetTableA
update with SpreadsheetTableB previous download.

So, if this is the right way to solve my issue, I need some advice on a fool
proof naming convention to prevent this from happening. Perhaps an extra
field in the table that holds the previous spreadsheet names that indicates
which table the spreadsheet is applicable to would do the trick. I'm loathe
to start hardcoding names or indicators to help solve this problem.

On the other hand, I'm very open to other suggestions of how to accomplish
notifying the user that there are updates available on my ftp site for tables
within my application.

Thank you.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200604/1
Apr 25 '06 #1
2 3055
Hi,

Each time you put a new version of you spreadsheet, put a script files on
your FTP with a release version like 1,2,3...., and download this script and
compare this version with the local script and use my code to download if
necessary.
Best regards (sorry for my cheap english)

Robert Simard
Logipro
http://www.logicielappui.com/tips

'// Code Start
Option Compare Database
Option Explicit

Private Const MAX_PATH = 260
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const INTERNET_INVALID_PORT_NUMBER = 0
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3
Private Const INTERNET_FLAG_PASSIVE = &H8000000
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_MULTIPART = &H200000

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

Global FTP_Server As String
Global FTP_User As String
Global FTP_PassW As String
Global glbSize As String
Global StopTransfert As Boolean

Const FTP_UAgent = "FTP Demo"
Dim hOpen As Long
Dim hConnection As Long
Dim Transfer As Long
Dim hFile As Long

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (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 InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
String, ByVal nServerPort As Integer, 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 InternetGetLastResponseInfo Lib "wininet.dll" Alias
"InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As
String, lpdwBufferLength As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet
As Long) As Integer
Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA"
(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long,
ByVal Flags As Long, ByVal Context As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As
Long, ByVal sBuffer As String, ByVal lNumberOfBytesToRead As Long,
lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetWriteFile Lib "wininet.dll" (ByVal hFile As
Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long,
dwNumberOfBytesWritten As Long) As Integer
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias
"FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String)
As Long

Public Function FTPConnect(FServer As String, _
FUser As String, _
FPass As String) As Boolean
'// Connection au FTP
FTPConnect = True
FTP_Server = FServer
FTP_User = FUser
FTP_PassW = FPass

DoCmd.Hourglass True

hOpen = InternetOpen(FTP_UAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
vbNullString, 0)

If hOpen <> 0 Then
hConnection = InternetConnect(hOpen, FTP_Server, _
INTERNET_INVALID_PORT_NUMBER, _
FTP_User, _
FTP_PassW, _
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE, 0)
If hConnection = 0 Then
MsgBox "Impossible de se connecter au serveur FTP avec le nom
d'utilisateur et le mot de passe spécifiés.", vbExclamation, "Erreur de
connection"
FTPDisconnect
FTPConnect = False
End If
Else
MsgBox "Impossible d'ouvrir votre connection Internet.",
vbExclamation, "Erreur de connection"
FTPConnect = False
End If

DoCmd.Hourglass False
End Function

Public Function DownloadFTPFiles(strFile As String, strNewFile As String,
lngFileSize As Long) As Boolean
'// Télécharge un fichier sur un site FTP
Dim hFile As Long
Dim sBuffer As String
Dim sReadBuffer As String * 4096 'par tranche de 4k
Dim lNumberOfBytesRead As Long
Dim bDoLoop As Boolean
Dim Sum As Long

hFile = FtpOpenFile(hConnection, Trim(strFile), GENERIC_READ, Transfer,
0)
Open strNewFile For Binary Access Write As #2

bDoLoop = True
While bDoLoop
If StopTransfert = True Then GoTo StopGetFiles
sReadBuffer = vbNullChar
bDoLoop = InternetReadFile(hFile, sReadBuffer, Len(sReadBuffer),
lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Sum = Sum + lNumberOfBytesRead
'UpdateProgressMeter "Téléchargement", Sum, Val(lngFileSize),
"Téléchargement", Val(Sum)
Wend

Put #2, , sBuffer

StopGetFiles:
Close #2
InternetCloseHandle (hFile)

End Function

Public Function UploadFTPFiles(lFile, ShortFile, FileSize As Long)
'// Envois un fichier sur un FTP
'//Exemple :SendFTPFiles "c:\bob.exe", "bob.exe"

Dim Data(99) As Byte ' array of 100 elements 0 to 99
Dim Written As Long
Dim Size As Long
Dim Sum As Long
Dim j As Long

Sum = 0
j = 0

hFile = FtpOpenFile(hConnection, ShortFile, GENERIC_WRITE, Transfer, 0)
If hFile = 0 Then Exit Function

Open lFile For Binary Access Read As #1
Size = LOF(1)
glbSize = Size

For j = 1 To Size \ 100
If StopTransfert = True Then GoTo StopSendFTPFiles
Get #1, , Data
If (InternetWriteFile(hFile, Data(0), 100, Written) = 0) Then Exit
Function

DoEvents
Sum = Sum + 100
'UpdatePB Sum, FileSize
Next j

Get #1, , Data

If (InternetWriteFile(hFile, Data(0), Size Mod 100, Written) = 0) Then Exit
Function

Sum = Sum + (Size Mod 100)
'UpdatePB Sum, FileSize (this is my forms progressbar)

Close #1
InternetCloseHandle (hFile)
Exit Function
StopSendFTPFiles:
Close #1
InternetCloseHandle (hFile)
hFile = FtpDeleteFile(hConnection, ShortFile)
glbSize = 0
End Function

Private Function GetStatus() As String
'// Retourne le status de le connection
Dim Buffer$, L&, Inf&, AA$

InternetGetLastResponseInfo Inf, vbNullString, L

If Inf Then
Buffer = String(L + 1, 0)
InternetGetLastResponseInfo Inf, Buffer, L
AA = Inf & " " & Buffer
Else
AA = " Ok"
End If

GetStatus = AA
End Function

Public Sub FTPDisconnect()
InternetCloseHandle hConnection
InternetCloseHandle hOpen
GetStatus
hConnection = 0
hOpen = 0
End Sub

Public Sub DelFTPFiles(fFiles As String)
FtpDeleteFile hConnection, fFiles
End Sub
'\\ Code End
Apr 26 '06 #2
Merci beucoup, Robert.

I'm going to compare your code with what I have. I may need to post again,
if I need some help in translating the french error messages to english.

P.S. your English is fine!

Logipro wrote:
Hi,

Each time you put a new version of you spreadsheet, put a script files on
your FTP with a release version like 1,2,3...., and download this script and
compare this version with the local script and use my code to download if
necessary.

Best regards (sorry for my cheap english)

Robert Simard
Logipro
http://www.logicielappui.com/tips

'// Code Start
Option Compare Database
Option Explicit

Private Const MAX_PATH = 260
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const INTERNET_INVALID_PORT_NUMBER = 0
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3
Private Const INTERNET_FLAG_PASSIVE = &H8000000
Private Const INTERNET_FLAG_RELOAD = &H80000000
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_MULTIPART = &H200000

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

Global FTP_Server As String
Global FTP_User As String
Global FTP_PassW As String
Global glbSize As String
Global StopTransfert As Boolean

Const FTP_UAgent = "FTP Demo"
Dim hOpen As Long
Dim hConnection As Long
Dim Transfer As Long
Dim hFile As Long

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (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 InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
String, ByVal nServerPort As Integer, 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 InternetGetLastResponseInfo Lib "wininet.dll" Alias
"InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As
String, lpdwBufferLength As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet
As Long) As Integer
Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA"
(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long,
ByVal Flags As Long, ByVal Context As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As
Long, ByVal sBuffer As String, ByVal lNumberOfBytesToRead As Long,
lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetWriteFile Lib "wininet.dll" (ByVal hFile As
Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long,
dwNumberOfBytesWritten As Long) As Integer
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias
"FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String)
As Long

Public Function FTPConnect(FServer As String, _
FUser As String, _
FPass As String) As Boolean
'// Connection au FTP
FTPConnect = True
FTP_Server = FServer
FTP_User = FUser
FTP_PassW = FPass

DoCmd.Hourglass True

hOpen = InternetOpen(FTP_UAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
vbNullString, 0)

If hOpen <> 0 Then
hConnection = InternetConnect(hOpen, FTP_Server, _
INTERNET_INVALID_PORT_NUMBER, _
FTP_User, _
FTP_PassW, _
INTERNET_SERVICE_FTP,
INTERNET_FLAG_PASSIVE, 0)

If hConnection = 0 Then
MsgBox "Impossible de se connecter au serveur FTP avec le nom
d'utilisateur et le mot de passe spécifiés.", vbExclamation, "Erreur de
connection"
FTPDisconnect
FTPConnect = False
End If
Else
MsgBox "Impossible d'ouvrir votre connection Internet.",
vbExclamation, "Erreur de connection"
FTPConnect = False
End If

DoCmd.Hourglass False
End Function

Public Function DownloadFTPFiles(strFile As String, strNewFile As String,
lngFileSize As Long) As Boolean
'// Télécharge un fichier sur un site FTP
Dim hFile As Long
Dim sBuffer As String
Dim sReadBuffer As String * 4096 'par tranche de 4k
Dim lNumberOfBytesRead As Long
Dim bDoLoop As Boolean
Dim Sum As Long

hFile = FtpOpenFile(hConnection, Trim(strFile), GENERIC_READ, Transfer,
0)
Open strNewFile For Binary Access Write As #2

bDoLoop = True
While bDoLoop
If StopTransfert = True Then GoTo StopGetFiles
sReadBuffer = vbNullChar
bDoLoop = InternetReadFile(hFile, sReadBuffer, Len(sReadBuffer),
lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
Sum = Sum + lNumberOfBytesRead
'UpdateProgressMeter "Téléchargement", Sum, Val(lngFileSize),
"Téléchargement", Val(Sum)
Wend

Put #2, , sBuffer

StopGetFiles:
Close #2
InternetCloseHandle (hFile)

End Function

Public Function UploadFTPFiles(lFile, ShortFile, FileSize As Long)
'// Envois un fichier sur un FTP
'//Exemple :SendFTPFiles "c:\bob.exe", "bob.exe"

Dim Data(99) As Byte ' array of 100 elements 0 to 99
Dim Written As Long
Dim Size As Long
Dim Sum As Long
Dim j As Long

Sum = 0
j = 0

hFile = FtpOpenFile(hConnection, ShortFile, GENERIC_WRITE, Transfer, 0)
If hFile = 0 Then Exit Function

Open lFile For Binary Access Read As #1
Size = LOF(1)
glbSize = Size

For j = 1 To Size \ 100
If StopTransfert = True Then GoTo StopSendFTPFiles
Get #1, , Data
If (InternetWriteFile(hFile, Data(0), 100, Written) = 0) Then Exit
Function

DoEvents
Sum = Sum + 100
'UpdatePB Sum, FileSize
Next j

Get #1, , Data

If (InternetWriteFile(hFile, Data(0), Size Mod 100, Written) = 0) Then Exit
Function

Sum = Sum + (Size Mod 100)
'UpdatePB Sum, FileSize (this is my forms progressbar)

Close #1
InternetCloseHandle (hFile)
Exit Function

StopSendFTPFiles:
Close #1
InternetCloseHandle (hFile)
hFile = FtpDeleteFile(hConnection, ShortFile)
glbSize = 0
End Function

Private Function GetStatus() As String
'// Retourne le status de le connection
Dim Buffer$, L&, Inf&, AA$

InternetGetLastResponseInfo Inf, vbNullString, L

If Inf Then
Buffer = String(L + 1, 0)
InternetGetLastResponseInfo Inf, Buffer, L
AA = Inf & " " & Buffer
Else
AA = " Ok"
End If

GetStatus = AA
End Function

Public Sub FTPDisconnect()
InternetCloseHandle hConnection
InternetCloseHandle hOpen
GetStatus
hConnection = 0
hOpen = 0
End Sub

Public Sub DelFTPFiles(fFiles As String)
FtpDeleteFile hConnection, fFiles
End Sub
'\\ Code End


--
Message posted via http://www.accessmonster.com
Apr 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthew Moran | last post by:
I am creating a series of downloadable articles, career tools, spreadsheets, etc. However, some of the content is for "registered" guest. The registrants are stored in a database and logon. I...
37
by: ajay | last post by:
How to make a web page getting refreshed after a given time interval automatically. HTML Code plz. Tx Ajay
4
by: ACaunter | last post by:
Can some please help me.. i've asked this question before and i'll get people writing back with links to http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx, or the easyzipunzip...
2
by: Jim S | last post by:
To my surprise and chagrin, newer versions of Access have disabled the functionality that lets users change the data in linked tables that point to a range in an Excel workbook. This is "because of...
0
by: HackingPSP | last post by:
I saw a lot of requests for a program like this, so I wrote it. Yeah, my site has "PSP software by Auri" but in this case it means "Pretty Sweet Programming" :) There's both a VS2005 add-in and a...
1
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy...
1
by: Curtis | last post by:
I am having a problem with the coding below that someone was trying to help me with in another website. I have been to several websites and hopefully here I can get it resolved. I inherited this...
1
by: Joey Nolan | last post by:
Hi, I have a PDF file on my site that I want to distribute freely but I want to be able to contact anyone who downloaded it to warn them about mistakes and modification and new versions and...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.