Results 1 to 3 of 3
  1. #1
    mtownend is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    4

    access - FTP Server

    Hi,

    I am Tring to use VB in access to Upload and Download files from a FTP sever. Does anyone have any standard code i can edit to achive this.

  2. #2
    mtownend is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    4
    Hi I have managed to find the code to upload i just need the code to download


    Function FTPFile(ByVal HostName As String, _
    ByVal UserName As String, _
    ByVal Password As String, _
    ByVal LocalFileName As String, _
    ByVal RemoteFileName As String, _
    ByVal sDir As String, _
    ByVal sMode As String) As Boolean

    On Error GoTo Err_Function

    ' Declare variables
    Dim hConnection, hOpen, hFile As Long ' Used For Handles
    Dim iSize As Long ' Size of file for upload
    Dim Retval As Variant ' Used for progress meter
    Dim iWritten As Long ' Used by InternetWriteFile to report bytes uploaded
    Dim iLoop As Long ' Loop for uploading chuncks
    Dim iFile As Integer ' Used for Local file handle
    Dim FileData(BUFFER_SIZE - 1) As Byte ' buffer array of BUFFER_SIZE (100) elements 0 to 99
    ' Open Internet Connecion
    hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
    ' Connect to FTP
    hConnection = InternetConnect(hOpen, HostName, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    ' Change Directory
    Call FtpSetCurrentDirectory(hConnection, sDir)
    ' Open Remote File
    hFile = FtpOpenFile(hConnection, RemoteFileName, GENERIC_WRITE, IIf(sMode = "Binary", FTP_TRANSFER_TYPE_BINARY, FTP_TRANSFER_TYPE_ASCII), 0)
    ' Check for successfull file handle
    If hFile = 0 Then
    MsgBox "Internet - Failed!"
    ShowError
    FTPFile = False
    GoTo Exit_Function
    End If
    ' Set Upload Flag to True
    FTPFile = True
    ' Get next file handle number
    iFile = FreeFile
    ' Open local file
    Open LocalFileName For Binary Access Read As iFile
    ' Set file size
    iSize = LOF(iFile)
    ' Iinitialise progress meter
    Retval = SysCmd(acSysCmdInitMeter, "Uploading File (" & RemoteFileName & ")", iSize / 1000)
    ' Loop file size
    For iLoop = 1 To iSize \ BUFFER_SIZE

    ' Update progress meter
    Retval = SysCmd(acSysCmdUpdateMeter, (BUFFER_SIZE * iLoop) / 1000)

    'Get file data
    Get iFile, , FileData

    ' Write chunk to FTP checking for success
    If InternetWriteFile(hFile, FileData(0), BUFFER_SIZE, iWritten) = 0 Then
    MsgBox "Upload - Failed!"
    ShowError
    FTPFile = False
    GoTo Exit_Function
    Else
    ' Check buffer was written
    If iWritten <> BUFFER_SIZE Then
    MsgBox "Upload - Failed!"
    ShowError
    FTPFile = False
    GoTo Exit_Function
    End If
    End If

    Next iLoop
    ' Handle remainder using MOD
    ' Update progress meter
    Retval = SysCmd(acSysCmdUpdateMeter, iSize / 1000)
    ' Get file data
    Get iFile, , FileData

    ' Write remainder to FTP checking for success
    If InternetWriteFile(hFile, FileData(0), iSize Mod BUFFER_SIZE, iWritten) = 0 Then
    MsgBox "Upload - Failed!"
    ShowError
    FTPFile = False
    GoTo Exit_Function
    Else
    ' Check buffer was written
    If iWritten <> iSize Mod BUFFER_SIZE Then
    MsgBox "Upload - Failed!"
    ShowError
    FTPFile = False
    GoTo Exit_Function
    End If
    End If

    Exit_Function:
    ' remove progress meter
    Retval = SysCmd(acSysCmdRemoveMeter)
    'close remote file
    Call InternetCloseHandle(hFile)
    'close local file
    Close iFile
    ' Close Internet Connection
    Call InternetCloseHandle(hOpen)
    Call InternetCloseHandle(hConnection)
    Exit Function
    Err_Function:
    MsgBox "Error in FTPFile : " & Err.Description
    GoTo Exit_Function
    End Function

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access and SQL Server on a VPN: Possible?
    By evander in forum Database Design
    Replies: 6
    Last Post: 02-03-2011, 10:53 AM
  2. Access 2010 vs SQL Server
    By mwolfod in forum Access
    Replies: 3
    Last Post: 10-18-2010, 04:25 PM
  3. Access and SQL Server?
    By evander in forum Database Design
    Replies: 2
    Last Post: 07-31-2010, 07:47 PM
  4. Access Frontend to Sql server db
    By ksukat in forum Import/Export Data
    Replies: 0
    Last Post: 06-08-2010, 01:35 PM
  5. Access / SQl Server Advantage.
    By caljohn527 in forum Queries
    Replies: 0
    Last Post: 01-24-2009, 06:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums