advanced FTP help needed

mdmilner

Well-known Member
Joined
Apr 30, 2003
Messages
1,362
I finally found a method to ftp that works without using sendkeys or shells to do ftp. It's from here:

http://www.mvps.org/access/modules/mdl0037.htm

Here is the stock code segment including the CLASS object URL_COMPONENTS and the function that breaks it.

Rich (BB code):
Option Compare Database
Option Explicit

'
'  Copyright (C)1998-99 Dev Ashish and Terry Kreft, All Rights Reserved
'  The Access Web (http://home.att.net/~dashish)
'  Comments and bug reports can be emailed to us
'  Dev Ashish (dash10@hotmail.com) ; Terry Kreft (terry.kreft@mps.co.uk)
'
'

Private Type URL_COMPONENTS
  dwStructSize As Long
  lpszScheme As String
  dwSchemeLength As Long
  nScheme As Long
  lpszHostName As String
  dwHostNameLength As Long
  nPort As Long
  lpszUserName As String
  dwUserNameLength As Long
  lpszPassword As String
  dwPasswordLength As Long
  lpszUrlPath As String
  dwUrlPathLength As Long
  lpszExtraInfo As String
  dwExtraInfoLength As Long
End Type

Private mstrURL As String
Private mstrDestination As String
Private mblnConnectState As Boolean
Private mblnOverWrite As Boolean
Private hFile As Long
Private hSession As Long
Private lnghWnd As Long
Private hInet As Long
Private hFTP As Long
Private hURL As Long
Private mlngSize As Long
Private mblnPromptForFile As Boolean
Private mtURLInfo As URL_COMPONENTS
Private mcolRemoteDir As Collection
Private mstrSrcFile As String
Private mblnUpload As Boolean
Private mblnUseProxy As Boolean
Private mblnCreateRemoteDir As Boolean
Private mintErrorTrap As Integer

Private Function fParseURL(tURLInfo As URL_COMPONENTS, ByVal strURL As String) As Boolean
Dim lngLen As Long, strBuffer As String
Dim lngRet As Long, strURLLocal As String

  strBuffer = String$(MAX_BUFFER, 0)
  lngLen = Len(strBuffer)
  lngRet = apiInetCanonicalizeUrl(strURL, strBuffer, lngLen, ICU_BROWSER_MODE)
  If Not lngRet = 0 Then
    strURLLocal = Left$(strBuffer, lngLen)
    With tURLInfo
      .lpszScheme = String$(MAX_BUFFER, 0)
      .dwSchemeLength = MAX_BUFFER
      .nScheme = INTERNET_SCHEME_UNKNOWN
      .lpszHostName = String$(MAX_BUFFER, 0)
      .dwHostNameLength = MAX_BUFFER
      .dwStructSize = Len(tURLInfo)
      .nPort = 0
      .lpszUserName = String$(MAX_BUFFER, 0)
      .dwUserNameLength = MAX_BUFFER
      .lpszPassword = String$(MAX_BUFFER, 0)
      .dwPasswordLength = MAX_BUFFER
      .lpszUrlPath = String$(MAX_BUFFER, 0)
      .dwUrlPathLength = MAX_BUFFER
      .lpszExtraInfo = String$(MAX_BUFFER, 0)
      .dwExtraInfoLength = MAX_BUFFER
    End With
    lngRet = apiInetCrackUrl(strURLLocal, Len(strURLLocal), _
                      ICU_ESCAPE, tURLInfo)
    If lngRet = 0 Then
      fParseURL = False
    Else
      fParseURL = True
      With tURLInfo
        .lpszExtraInfo = fTrimNull(.lpszExtraInfo)
        .lpszHostName = fTrimNull(.lpszHostName)
        .lpszPassword = fTrimNull(.lpszPassword)
        .lpszScheme = fTrimNull(.lpszScheme)
        .lpszUrlPath = fTrimNull(.lpszUrlPath)
        .lpszUserName = fTrimNull(.lpszUserName)
      End With
    End If
  End If
End Function

My workaround is to comment out the error checking in this, bypassing basically everything it does and add these lines near the end.

tURLInfo.lpszHostName = "csxtsysb.csxt.csx.com"
tURLInfo.lpszPassword = "actual_password"
tURLInfo.lpszUrlPath = "'FLRSFCP.FOC.DSK15Q.DATA'"
tURLInfo.lpszUserName = "actual_login"
tURLInfo.lpszScheme = 0
fParseURL = True

Adding these lines makes it work. I think the problem is that I do not understand what the function does completely and how it’s supposed to extract the values. I’m not sending the right data into the Buffer?

I'm looking for any input I can get. While I can obviously get this working by modifying/bypassing this functionality - I'd rather see if I can get it working AND possibly learning something. I know I avoid commenting when I'm not sure on something - so please feel free to send a direct message if you don't wish to post to the forum.

Mike
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Ok, darn it. Figured it out finally although I did take a little input from Mr Ashish.

Problem really was a malformed url. Needed to be:

ftp://login:password@website/filelocation

I've still got an error when it's parsing the file location (it's keeping the "/") but that's either VB fixable or most likely a syntax error on my part.

Code:
        If Left(.lpszUrlPath, 1) = "/" Then
          .lpszUrlPath = Mid(.lpszUrlPath, 2, Len(.lpszUrlPath) - 1)
        End If

Later,
Mike
 
Upvote 0

Forum statistics

Threads
1,221,683
Messages
6,161,264
Members
451,692
Latest member
jmaskin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top