FTP from MS Access?
Question posted by: tekknow
(Guest)
on
November 13th, 2005 02:31 AM
How can one FTP to one's site via VBA (or built in Access control)? Examples
of required funtions would be: file upload, download, delete, rename, move,
and director listing.
Thanks in advance
16
Answers Posted
This is what I use:
Option Compare Database
Option Explicit
Private Const ModEro = 9100
Public Function FTP(ascii As Boolean, send As Boolean, pathname As String,
FileName As String, server As String, serverpathname As String,
serverfilename As String, username As String, password As String, Optional
RstN As String, Optional RstFld As String)
Dim Fs As Object
Dim a As Variant
Dim RST As Recordset
Const script = "__temp_script.tmp"
'---
Dim asciiType As String
If ascii = True Then asciiType = "ascii" Else asciiType = "binary"
'---
Dim SendType As String
If send = True Then SendType = "Put " Else SendType = "Get "
'---create and open the file
Set Fs = CreateObject("Scripting.FileSystemObject")
Set a = Fs.CreateTextFile(pathname & "\" & script, True)
' write all the lines to the file
a.writeline "lcd " & Chr(34) & pathname & Chr(34)
a.writeline "open " & server
a.writeline username
a.writeline password
If (serverpathname <> "") Then a.writeline "cd " & serverpathname
If (ascii) Then
a.writeline asciiType
Else
a.writeline asciiType
End If
If RstN <> "" Then
Set RST = CurrentDb.OpenRecordset(RstN)
Do While Not RST.EOF
FileName = RST.Fields(RstFld) & ".html"
serverfilename = FileName
a.writeline SendType & FileName & " " & serverfilename
RST.MoveNext
Loop
Else
a.writeline SendType & FileName & " " & serverfilename
End If
a.writeline "bye"
'close file
a.Close
sFTP (pathname & "\" & script)
End Function
Private Sub sFTP(stSCRFile As String)
Dim stSysDir As String
'---
stSysDir = Environ$("COMSPEC")
stSysDir = Left$(stSysDir, Len(stSysDir) - Len(Dir(stSysDir)))
Call Shell(stSysDir & "ftp.exe -s:" & stSCRFile, vbNormalFocus)
End Sub
On Mon, 02 Aug 2004 02:57:55 GMT, "tekknow"
<tech-nician0154357@hotmail.com> wrote:
Check out the wininet DLL, e.g. at
http://msdn.microsoft.com/library/d...t_reference.asp.
It provides FTP and more without running ugly command-line windows.
-Tom.
[color=blue]
>How can one FTP to one's site via VBA (or built in Access control)? Examples
>of required funtions would be: file upload, download, delete, rename, move,
>and director listing.
>
>Thanks in advance
>[/color]
"tekknow" <tech-nician0154357@hotmail.com> wrote:
[color=blue]
>How can one FTP to one's site via VBA (or built in Access control)? Examples
>of required funtions would be: file upload, download, delete, rename, move,
>and director listing.[/color]
Microsoft Access & TCP/IP programming
http://www.granite.ab.ca/access/tcpipprogramming.htm
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
RE/[color=blue]
>How can one FTP to one's site via VBA (or built in Access control)? Examples
>of required funtions would be: file upload, download, delete, rename, move,
>and director listing.[/color]
One thing to watch for: Proxies. Your code has to be different depending on
whether the app is going through a proxy or not. That drove me nuts for a
couple days until I finally caught on.
--
PeteCresswell
Tony Toews <ttoews@telusplanet.net> wrote in message news:<3jvsg0ltudl534jmcvvq5d0rl685qr2t3c@4ax.com>...[color=blue]
> "tekknow" <tech-nician0154357@hotmail.com> wrote:
>[color=green]
> >How can one FTP to one's site via VBA (or built in Access control)? Examples
> >of required funtions would be: file upload, download, delete, rename, move,
> >and director listing.[/color]
>
> Microsoft Access & TCP/IP programming
> http://www.granite.ab.ca/access/tcpipprogramming.htm
>
> Tony[/color]
Tony,
Nice information. The fifth link is broken though.
http://www.planet-source-code.com/x...ts/ShowCode.htm
James A. Fortune
On Mon, 02 Aug 2004 02:57:55 GMT, "tekknow"
<tech-nician0154357@hotmail.com> wrote:
[color=blue]
>How can one FTP to one's site via VBA (or built in Access control)? Examples
>of required funtions would be: file upload, download, delete, rename, move,
>and director listing.
>
>Thanks in advance
>
>[/color]
Give this a try...
http://www.mvps.org/access/modules/mdl0037.htm
I have had good luck with the class in A97, I haven't tried it in
others.
- Jim
"(Pete Cresswell)" <x@y.z> wrote:
[color=blue][color=green]
>>How can one FTP to one's site via VBA (or built in Access control)? Examples
>>of required funtions would be: file upload, download, delete, rename, move,
>>and director listing.[/color]
>
>One thing to watch for: Proxies. Your code has to be different depending on
>whether the app is going through a proxy or not. That drove me nuts for a
>couple days until I finally caught on.[/color]
Thanks for the warning. I'll be working on some similar code soon.
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Thanks, this will work for Put and Get, bt, I'll still need to research
directory listings and renames.
Incidentally, in order to use filenames with spaces, this line:
a.writeline SendType & FileName & " " & serverfilename
had to be changed to read thus:
a.writeline SendType & """" & FileName & """" & " " & """" &
serverfilename & """"
Thanks again.
"WindAndWaves" <access@ngaru.com> wrote in message
news:nJjPc.8007$N77.399721@news.xtra.co.nz...[color=blue]
> This is what I use:
>
> Option Compare Database
> Option Explicit
> Private Const ModEro = 9100
>
> Public Function FTP(ascii As Boolean, send As Boolean, pathname As String,
> FileName As String, server As String, serverpathname As String,
> serverfilename As String, username As String, password As String, Optional
> RstN As String, Optional RstFld As String)
> Dim Fs As Object
> Dim a As Variant
> Dim RST As Recordset
> Const script = "__temp_script.tmp"
> '---
> Dim asciiType As String
> If ascii = True Then asciiType = "ascii" Else asciiType = "binary"
> '---
> Dim SendType As String
> If send = True Then SendType = "Put " Else SendType = "Get "
> '---create and open the file
> Set Fs = CreateObject("Scripting.FileSystemObject")
> Set a = Fs.CreateTextFile(pathname & "\" & script, True)
> ' write all the lines to the file
> a.writeline "lcd " & Chr(34) & pathname & Chr(34)
> a.writeline "open " & server
> a.writeline username
> a.writeline password
> If (serverpathname <> "") Then a.writeline "cd " & serverpathname
> If (ascii) Then
> a.writeline asciiType
> Else
> a.writeline asciiType
> End If
> If RstN <> "" Then
> Set RST = CurrentDb.OpenRecordset(RstN)
> Do While Not RST.EOF
> FileName = RST.Fields(RstFld) & ".html"
> serverfilename = FileName
> a.writeline SendType & FileName & " " & serverfilename
> RST.MoveNext
> Loop
> Else
> a.writeline SendType & FileName & " " & serverfilename
> End If
> a.writeline "bye"
> 'close file
> a.Close
> sFTP (pathname & "\" & script)
> End Function
>
>
>
> Private Sub sFTP(stSCRFile As String)
> Dim stSysDir As String
> '---
> stSysDir = Environ$("COMSPEC")
> stSysDir = Left$(stSysDir, Len(stSysDir) - Len(Dir(stSysDir)))
> Call Shell(stSysDir & "ftp.exe -s:" & stSCRFile, vbNormalFocus)
> End Sub
>
>
>
>[/color]
Looks like everything I need, short of the aspirin. I'll keep this in mind,
but it's a bit more intense than I hoped for. Then again, learning is always
a good thing (as long as your learning a good thing ;-)
Thanks again
"Tom van Stiphout" <no.spam.tom7744@cox.net> wrote in message
news:ilgsg051cpce14tmcuu1k5orpm3i2evtlg@4ax.com... [color=blue]
> On Mon, 02 Aug 2004 02:57:55 GMT, "tekknow"
> <tech-nician0154357@hotmail.com> wrote:
>
> Check out the wininet DLL, e.g. at
>[/color]
http://msdn.microsoft.com/library/d...t_reference.asp.[color=blue]
> It provides FTP and more without running ugly command-line windows.
>
> -Tom.
>
>[color=green]
> >How can one FTP to one's site via VBA (or built in Access control)?[/color][/color]
Examples[color=blue][color=green]
> >of required funtions would be: file upload, download, delete, rename,[/color][/color]
move,[color=blue][color=green]
> >and director listing.
> >
> >Thanks in advance
> >[/color]
>
>[/color]
I haven't even checked these out yet, but coming from you,I"m sure there's
great info here. I'll be doing some reading this week, I can see.
Thanks a million for the links.
"Tony Toews" <ttoews@telusplanet.net> wrote in message
news:3jvsg0ltudl534jmcvvq5d0rl685qr2t3c@4ax.com... [color=blue]
> "tekknow" <tech-nician0154357@hotmail.com> wrote:
>[color=green]
> >How can one FTP to one's site via VBA (or built in Access control)?[/color][/color]
Examples[color=blue][color=green]
> >of required funtions would be: file upload, download, delete, rename,[/color][/color]
move,[color=blue][color=green]
> >and director listing.[/color]
>
> Microsoft Access & TCP/IP programming
> http://www.granite.ab.ca/access/tcpipprogramming.htm
>
> Tony
> --
> Tony Toews, Microsoft Access MVP
> Please respond only in the newsgroups so that others can
> read the entire thread of messages.
> Microsoft Access Links, Hints, Tips & Accounting Systems at
> http://www.granite.ab.ca/accsmstr.htm
>[/color]
Dear TekMaster
I think you are in the same boat as I am, keeping it simple - as long as it
works then that is great.
I would prefer to use some of the other options listed by the other users,
but they seem a lot harder to implement and more importantly, less portable.
If you type FTP in the windows run prompt and then from the prompt type
help, then you get all the commands that are available.
you can then type help close, for example, to find out about the close
command.
Thanks also for your
tekknow wrote:[color=blue]
> Thanks, this will work for Put and Get, bt, I'll still need to research
> directory listings and renames.[/color]
You can use the same sort of thing, just write out the script file,
execute it like:
Shell "ftp -s MyScript.ftp > output.txt"
You can then read the output.txt file, I use this a lot, my first error
check is to look for lines with val() >499 as these are errors. In this
way I also check (using ls) for files already existing on the FTP server.
--
Error reading sig - A)bort R)etry I)nfluence with large hammer
Thanks a bunch, Trevor, I was not sure how to output a log file. I'll be
playing with this for a while, for sure.
Thanks again.
"Trevor Best" <nospam@localhost> wrote in message
news:410f4114$0$9615$afc38c87@auth.uk.news.easynet .net...[color=blue]
> tekknow wrote:[color=green]
> > Thanks, this will work for Put and Get, bt, I'll still need to research
> > directory listings and renames.[/color]
>
> You can use the same sort of thing, just write out the script file,
> execute it like:
>
> Shell "ftp -s MyScript.ftp > output.txt"
>
> You can then read the output.txt file, I use this a lot, my first error
> check is to look for lines with val() >499 as these are errors. In this
> way I also check (using ls) for files already existing on the FTP server.
>
> --
> Error reading sig - A)bort R)etry I)nfluence with large hammer
>[/color]
I think the only thing I don't like about this is the command prompt, which
may confuse the user (this is for one of my kids, actually).
Thanks for your assist, though. I am using our code for now, since I have no
time to learn the fancy stuff right now.
"WindAndWaves" <access@ngaru.com> wrote in message
news:UWEPc.8429$N77.415852@news.xtra.co.nz...[color=blue]
> Dear TekMaster
>
> I think you are in the same boat as I am, keeping it simple - as long as[/color]
it[color=blue]
> works then that is great.
>
> I would prefer to use some of the other options listed by the other users,
> but they seem a lot harder to implement and more importantly, less[/color]
portable.[color=blue]
> If you type FTP in the windows run prompt and then from the prompt type
> help, then you get all the commands that are available.
>
> you can then type help close, for example, to find out about the close
> command.
>
> Thanks also for your
>
>
>[/color]
Dear Trevor,
I tried to use that > output.txt, but it does not work, do you have any
hints on that? I just seemed to crash.
WindAndWaves wrote:[color=blue]
> Dear Trevor,
>
> I tried to use that > output.txt, but it does not work, do you have any
> hints on that? I just seemed to crash.
>
>[/color]
Maybe Access thinks "> output.txt" is part of the file name to execute?
I haven't tested this, perhaps you need to put the command into a batch
file then execute that.
--
Error reading sig - A)bort R)etry I)nfluence with large hammer
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 196,897 network members.
Top Community Contributors
|