Just download from FTP

R

RD

Hi all,

Hey? I need to just download a known file from a known folder on an FTP server.
I grabbed the Internet Data Transfer Library module written by Dev and Terry
from the MVP site but, that's way overkill for what I'm trying to do. It's a
very involved module and I'm having a hard time wrapping my head around it.

Anybody want to help me break this down to the basics? The assumptions are that
the file on the server is overwritten each month and I'm going to be overwriting
the local file each month with the new one. The file name never changes, the
folders never change.

Thanks for any help,
RD


FTP address: ftp://10.21.16.112/Monthly/
Local folder: C:\Jobs\Extracts\
File name: FEA035B.TXT

Below is the pertinent routine (I think)

Public Sub WriteFTPDataToFile()
On Error GoTo ErrHandler

Dim lngRet As Long
Dim lngBytesRead As Long
Dim lngFlags As Long
Dim lngBytesWritten As Long
Dim lngTotalBytesWritten As Long
Dim abytData() As Byte
Dim strHost As String
Dim strFile As String
Dim strDir As String
Const conERR_GENERIC = vbObjectError + 100
Const conFILE_EXISTS = vbObjectError + 200

If mblnUpload Then Err.Raise mconERR_WRONG_OPERATION

If (Me.FileExists And Not mblnOverWrite) Or mblnPromptForFile Then
If lnghWnd = 0 Then lnghWnd = apiGetActiveWindow()
mstrDestination = fGetNewFileName("Please select a" _
& " new name for the destination file.", lnghWnd, False)
If mstrDestination = vbNullString Then Err.Raise _
conERR_GENERIC
End If

Call SysCmd(acSysCmdInitMeter, "Downloading file '" & _
mtURLInfo.lpszUrlPath & "'...", 100)


'Create the destination file
hFile = apiCreateFile(mstrDestination, _
GENERIC_READ Or GENERIC_WRITE, _
0&, 0&, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0&)
If hFile = INVALID_HANDLE_VALUE Then Err.Raise conERR_GENERIC

'Read in MAX_CHUNK Chunk
Do
ReDim abytData(MAX_CHUNK)
lngRet = apiInetReadFile(hFTP, _
abytData(0), _
MAX_CHUNK, _
lngBytesRead)
Call apiWriteFile(hFile, abytData(0), MAX_CHUNK, _
lngBytesWritten, 0&)
lngTotalBytesWritten = lngTotalBytesWritten + lngBytesWritten
Call SysCmd(acSysCmdUpdateMeter, CInt(lngTotalBytesWritten / mlngSize))
Loop Until lngRet <> 0 And lngBytesRead = 0

ExitHere:
On Error Resume Next
Call SysCmd(acSysCmdRemoveMeter)
Exit Sub
ErrHandler:
Select Case Err.Number
Case conERR_GENERIC:
'Do Nothing
Case mconERR_WRONG_OPERATION:
Err.Raise mconERR_WRONG_OPERATION, "FTP::WriteFTPDataToFile", _
"Wrong transfer method selected."
Case Else:
Err.Raise Err.Number, "FTP::WriteFTPDataToFile", Err.Description
End Select
Resume ExitHere
End Sub
 
R

RD

Thanks David. That opens it up real nice but I need to download it onto the
local drive.

Alberts suggestion is going to work for me.

Thanks again
RD
 
R

RD

Thanks Albert. Either I'm a bit thick-headed today or it wasn't really that
simple. :)
It took a while to get it working. My fault, really. I lied a little about the
folder names not changing. They change just a little bit so I had to figure out
how to build the code to create a script at runtime.

I got it working ... and then broke it ... and then got it working again.

Thanks again,
RD
 

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

Similar Threads


Top