ftp file automation

R

roger dave

I need to ftp a db object to a web address...the only
thing is I need to automate the whole process so that when
the user clicks on a button automatically the file will be
ftp'd to the web address. Unfortunately I cannot use the
Macros. i need to use code...anyone has any code to do
this?
 
R

Richard Choate

I have the code but it is not quick & easy. After looking into this
thoroughly for a project for my client, I determined that the best (and
maybe only decent) way is to use API calls. The code uses several API
functions I have stored in one module, and then some form code to call the
functions and ftp the db back and forth from the web server.

I looked into the Microsoft INET control that comes with Office Developer,
but after testing it I found it to be wholly inadequate for all but the
simplest of situations (only anonymous server worked. No password). Also,
you would have to package the control with a db app because you can't just
send it to someone who doesn't have Developer. Meanwhile, the API calls
worked great. Check the KB or the VBA Developers Handbook & see if you can
find the functions for this. It is a lot of code to just post here.
Richard Choate


I need to ftp a db object to a web address...the only
thing is I need to automate the whole process so that when
the user clicks on a button automatically the file will be
ftp'd to the web address. Unfortunately I cannot use the
Macros. i need to use code...anyone has any code to do
this?
 
J

Joe Fallon

Richard,
I also use the API for ftp. (In VB.Net I found a class that works fine.)
But I tested the ActiveX control and it worked fine and was quite simple to
use.
It allowed log-in UID and PWD information.

I think I got mine from VB6 though.

Just drop this on a form:
InetCtls.Inet.1


Private Sub ftpDownloadButton_Click()

With Inet1
.URL = txtURLbox
.UserName = txtUID
.Password = txtPWD
.Execute , "GET " & txtServerPath & " " & txtLocalPath
End With

End Sub
 
R

Richard Choate

Joe,
Not only did I test this thing quite thoroughly on my own, I ended up using
Microsoft paid support over it. They tried it on a private server and were
also unable to make it work well. I think it would connect and maybe get a
directory list, but it would not allow the transfer of my files in both
directions. This was the case for the MS guys also. I just don't trust it.
Anyway, you know how it is. I would have to package the thing for someone to
use it, and that just isn't practical for your basic Access database.

By the way, your code looks *VERY* familiar. I tried in myself.

Thanks,

Richard

Richard,
I also use the API for ftp. (In VB.Net I found a class that works fine.)
But I tested the ActiveX control and it worked fine and was quite simple to
use.
It allowed log-in UID and PWD information.

I think I got mine from VB6 though.

Just drop this on a form:
InetCtls.Inet.1


Private Sub ftpDownloadButton_Click()

With Inet1
.URL = txtURLbox
.UserName = txtUID
.Password = txtPWD
.Execute , "GET " & txtServerPath & " " & txtLocalPath
End With

End Sub
 
Joined
Feb 24, 2006
Messages
1
Reaction score
0
Quick and dirty...

I had a similar problem, and not being that familiar with Access I decided to build an ftp batch file on the fly, call the Windows command prompt with the batch file, and wait for the command prompt to finish. It works, but it might not be pretty...

Example:

Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
...
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
...
Private Function ShellProgramAndWait(ProgramName As String, Prompt As String, Windowstyle As Integer) As Boolean
Dim hHandle As Long, pid As Long
pid = Shell(ProgramName, Windowstyle)
If pid <> 0 Then
hHandle = OpenProcess(SYNCHRONIZE, 0&, pid)
WaitForSingleObject hHandle, INFINITE
ShellProgramAndWait = True
Else
ShellProgramAndWait = False
End If
End Function
...
I copied the code above from someone else...
...
Public Function ListFTPContents(IPAddress As String, username As String, password As String, remotedir As String, batchfile As String, resultsfile As String, strTable As String) As Integer

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(batchfile, True)
a.WriteLine ("open " & IPAddress)
a.WriteLine (username)
a.WriteLine (password)
a.WriteLine ("cd " & Chr(34) & remotedir & Chr(34)) ' or any other valid ftp command
a.WriteLine ("Dir")
a.WriteLine ("Quit")
a.Close

commandline = "cmd /U /C " & Chr(34) & "ftp -s:" & Chr(34) & batchfile_
& Chr(34) & " >" & Chr(34) & resultsfile & Chr(34) & Chr(34)
shellresult = ShellProgramAndWait(commandline, "FTP", vbHide)
If shellresult = False Then GoTo PROC_EXIT

...
You can then parse the resultsfile for the results of the operations.

Regards,
swedela
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top