473,799 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SpreadsheetTabl eA update with SpreadsheetTabl eA
previous download, it may get confused and now compare SpreadsheetTabl eA
update with SpreadsheetTabl eB 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.c om
http://www.accessmonster.com/Uwe/For...ccess/200604/1
Apr 25 '06 #1
2 3082
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_T YPE_PRECONFIG = 0
Private Const INTERNET_OPEN_T YPE_DIRECT = 1
Private Const INTERNET_OPEN_T YPE_PROXY = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const INTERNET_INVALI D_PORT_NUMBER = 0
Private Const INTERNET_SERVIC E_FTP = 1
Private Const INTERNET_SERVIC E_GOPHER = 2
Private Const INTERNET_SERVIC E_HTTP = 3
Private Const INTERNET_FLAG_P ASSIVE = &H8000000
Private Const INTERNET_FLAG_R ELOAD = &H80000000
Private Const INTERNET_FLAG_K EEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_M ULTIPART = &H200000

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttribute s As Long
ftCreationTime As FILETIME
ftLastAccessTim e 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.dl l" Alias
"InternetOp enA" (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.dl l" Alias
"InternetConnec tA" (ByVal hInternetSessio n 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 InternetGetLast ResponseInfo Lib "wininet.dl l" Alias
"InternetGetLas tResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As
String, lpdwBufferLengt h As Long) As Long
Private Declare Function InternetCloseHa ndle Lib "wininet.dl l" (ByVal hInet
As Long) As Integer
Private Declare Function FtpOpenFile Lib "wininet.dl l" Alias "FtpOpenFil eA"
(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 InternetReadFil e Lib "wininet.dl l" (ByVal hFile As
Long, ByVal sBuffer As String, ByVal lNumberOfBytesT oRead As Long,
lNumberOfBytesR ead As Long) As Integer
Private Declare Function InternetWriteFi le Lib "wininet.dl l" (ByVal hFile As
Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long,
dwNumberOfBytes Written As Long) As Integer
Private Declare Function FtpDeleteFile Lib "wininet.dl l" Alias
"FtpDeleteFileA " (ByVal hFtpSession As Long, ByVal lpszFileName As String)
As Long

Public Function FTPConnect(FSer ver 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(FT P_UAgent, INTERNET_OPEN_T YPE_DIRECT, vbNullString,
vbNullString, 0)

If hOpen <> 0 Then
hConnection = InternetConnect (hOpen, FTP_Server, _
INTERNET_INVALI D_PORT_NUMBER, _
FTP_User, _
FTP_PassW, _
INTERNET_SERVIC E_FTP,
INTERNET_FLAG_P ASSIVE, 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 DownloadFTPFile s(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 lNumberOfBytesR ead As Long
Dim bDoLoop As Boolean
Dim Sum As Long

hFile = FtpOpenFile(hCo nnection, 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 = InternetReadFil e(hFile, sReadBuffer, Len(sReadBuffer ),
lNumberOfBytesR ead)
sBuffer = sBuffer & Left$(sReadBuff er, lNumberOfBytesR ead)
If Not CBool(lNumberOf BytesRead) Then bDoLoop = False
Sum = Sum + lNumberOfBytesR ead
'UpdateProgress Meter "Téléchargement ", Sum, Val(lngFileSize ),
"Téléchargement ", Val(Sum)
Wend

Put #2, , sBuffer

StopGetFiles:
Close #2
InternetCloseHa ndle (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(hCo nnection, 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 StopSendFTPFile s
Get #1, , Data
If (InternetWriteF ile(hFile, Data(0), 100, Written) = 0) Then Exit
Function

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

Get #1, , Data

If (InternetWriteF ile(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
InternetCloseHa ndle (hFile)
Exit Function
StopSendFTPFile s:
Close #1
InternetCloseHa ndle (hFile)
hFile = FtpDeleteFile(h Connection, ShortFile)
glbSize = 0
End Function

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

InternetGetLast ResponseInfo Inf, vbNullString, L

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

GetStatus = AA
End Function

Public Sub FTPDisconnect()
InternetCloseHa ndle hConnection
InternetCloseHa ndle hOpen
GetStatus
hConnection = 0
hOpen = 0
End Sub

Public Sub DelFTPFiles(fFi les 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_T YPE_PRECONFIG = 0
Private Const INTERNET_OPEN_T YPE_DIRECT = 1
Private Const INTERNET_OPEN_T YPE_PROXY = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const INTERNET_INVALI D_PORT_NUMBER = 0
Private Const INTERNET_SERVIC E_FTP = 1
Private Const INTERNET_SERVIC E_GOPHER = 2
Private Const INTERNET_SERVIC E_HTTP = 3
Private Const INTERNET_FLAG_P ASSIVE = &H8000000
Private Const INTERNET_FLAG_R ELOAD = &H80000000
Private Const INTERNET_FLAG_K EEP_CONNECTION = &H400000
Private Const INTERNET_FLAG_M ULTIPART = &H200000

Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
dwFileAttribute s As Long
ftCreationTime As FILETIME
ftLastAccessTim e 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.dl l" 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.dl l" Alias
"InternetConne ctA" (ByVal hInternetSessio n 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 InternetGetLast ResponseInfo Lib "wininet.dl l" Alias
"InternetGetLa stResponseInfoA " (lpdwError As Long, ByVal lpszBuffer As
String, lpdwBufferLengt h As Long) As Long
Private Declare Function InternetCloseHa ndle Lib "wininet.dl l" (ByVal hInet
As Long) As Integer
Private Declare Function FtpOpenFile Lib "wininet.dl l" Alias "FtpOpenFil eA"
(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 InternetReadFil e Lib "wininet.dl l" (ByVal hFile As
Long, ByVal sBuffer As String, ByVal lNumberOfBytesT oRead As Long,
lNumberOfBytes Read As Long) As Integer
Private Declare Function InternetWriteFi le Lib "wininet.dl l" (ByVal hFile As
Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long,
dwNumberOfByte sWritten As Long) As Integer
Private Declare Function FtpDeleteFile Lib "wininet.dl l" Alias
"FtpDeleteFile A" (ByVal hFtpSession As Long, ByVal lpszFileName As String)
As Long

Public Function FTPConnect(FSer ver 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.Hourglas s True

hOpen = InternetOpen(FT P_UAgent, INTERNET_OPEN_T YPE_DIRECT, vbNullString,
vbNullString , 0)

If hOpen <> 0 Then
hConnection = InternetConnect (hOpen, FTP_Server, _
INTERNET_INVALI D_PORT_NUMBER, _
FTP_User, _
FTP_PassW, _
INTERNET_SERVIC E_FTP,
INTERNET_FLAG_ PASSIVE, 0)

If hConnection = 0 Then
MsgBox "Impossible de se connecter au serveur FTP avec le nom
d'utilisateu r 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.",
vbExclamatio n, "Erreur de connection"
FTPConnect = False
End If

DoCmd.Hourglass False
End Function

Public Function DownloadFTPFile s(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 lNumberOfBytesR ead As Long
Dim bDoLoop As Boolean
Dim Sum As Long

hFile = FtpOpenFile(hCo nnection, 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 = InternetReadFil e(hFile, sReadBuffer, Len(sReadBuffer ),
lNumberOfBytes Read)
sBuffer = sBuffer & Left$(sReadBuff er, lNumberOfBytesR ead)
If Not CBool(lNumberOf BytesRead) Then bDoLoop = False
Sum = Sum + lNumberOfBytesR ead
'UpdateProgress Meter "Téléchargement ", Sum, Val(lngFileSize ),
"Téléchargemen t", Val(Sum)
Wend

Put #2, , sBuffer

StopGetFiles :
Close #2
InternetCloseHa ndle (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(hCo nnection, 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 StopSendFTPFile s
Get #1, , Data
If (InternetWriteF ile(hFile, Data(0), 100, Written) = 0) Then Exit
Function

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

Get #1, , Data

If (InternetWriteF ile(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
InternetCloseH andle (hFile)
Exit Function

StopSendFTPFil es:
Close #1
InternetCloseHa ndle (hFile)
hFile = FtpDeleteFile(h Connection, ShortFile)
glbSize = 0
End Function

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

InternetGetLas tResponseInfo Inf, vbNullString, L

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

GetStatus = AA
End Function

Public Sub FTPDisconnect()
InternetCloseHa ndle hConnection
InternetCloseHa ndle hOpen
GetStatus
hConnection = 0
hOpen = 0
End Sub

Public Sub DelFTPFiles(fFi les 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
3752
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 want to ensure that someone registered cannot simply pass someone the path to the files for download. However, I am not creating an actual system user name for the folders where the various documents exist.
37
12754
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
1986
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 website... However, none of these are too easy to use.. one you have to pay $400 for, and the other is written in c# and i'm having difficulty changing it into asp.net so i can use it.. is it possible for anyone to show me the simpilist way to enter a...
2
2318
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 legal issues..." according to Office Support. I have other issues, specifically a couple of applications that do things such as calculate price updates in Access and read them back by means of update queries into the spreadsheets our marketing...
0
1571
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 standalone app (separate downloads, you don't need both). This is my second developer utility this year - my first being the Lorem Ipsum generator from a few weeks back. Download and get more info on WebPrecompiler at...
1
2720
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 for updating these tables via an ftp site: 1) Post a .mdb file to our ftp web site that contains the updated tables. My App code connects to the ftp site and gets the file name for any update files on the site. I already have code to do this...
1
2561
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 database and issue, and I apologize for a bit lengthy. The coding is located in the Event Procedure on the "On Open" property of the {rptLetter}: Sub cmdPrint_Click() 'Check if no results in any field, if all missing 'inform user and exit...
1
2079
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 updates... So I need some way to keep their email addresses and someway to prevent them sharing the link to the PDF file. I've seen some sites - with a form for the user to fill in
1
47492
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.