I am using some VBA coding to connect and download over FTP.
The code does not work when the path has a 'space' in it. Any ideas how to get round the issue?
I think its this line which goes wrong as the FTP software gets confused by the space which is inside sFLD
Print #iFile, "dir " & sFLD & " FileList.txt"
and you end up with the command
dir data/company/3rd april filelist.txt
I tried adding a trailing slash and quotes, neither seem to work:
dir data/company/3rd april/ filelist.txt
"dir data/company/3rd april" filelist.txt
The code does not work when the path has a 'space' in it. Any ideas how to get round the issue?
I think its this line which goes wrong as the FTP software gets confused by the space which is inside sFLD
Print #iFile, "dir " & sFLD & " FileList.txt"
and you end up with the command
dir data/company/3rd april filelist.txt
I tried adding a trailing slash and quotes, neither seem to work:
dir data/company/3rd april/ filelist.txt
"dir data/company/3rd april" filelist.txt
Code:
Public Function GetFtpFolderFileList(sSVR As String, sFLD As String, sUID As String, sPWD As String) As String
Dim sLocalFLD As String
Dim sScrFile As String
Dim iFile As Integer
Dim sExe As String
Const q As String * 1 = """"
On Error GoTo Err_Handler
sLocalFLD = CurrentProject.Path & "\" & sFLD
' will break if empty folder exist so error to pass
' must create folder first, so API calls work
On Error Resume Next
If Dir(sLocalFLD & "\") = "" Then MkDir (sLocalFLD)
On Error GoTo Err_Handler
sScrFile = sLocalFLD & "\FileDIR.scr"
If Dir(sScrFile) = "FileDIR.scr" Then Kill sScrFile
' Open a new text file to hold the FTP script and load it with
' the appropriate commands. (Thanks Dev Ashish !!!)
iFile = FreeFile
Open sScrFile For Output As iFile
Print #iFile, "open " & sSVR
Print #iFile, sUID
Print #iFile, sPWD
Print #iFile, "binary"
Print #iFile, "lcd " & q & sLocalFLD & q
Print #iFile, "dir " & sFLD & " FileList.txt"
Print #iFile, "bye"
Close #iFile
sExe = Environ$("COMSPEC")
sExe = Left$(sExe, Len(sExe) - Len(Dir(sExe)))
Debug.Print sScrFile
sExe = sExe & "ftp.exe -s:" & q & sScrFile & q
ShellWait sExe, vbHide
DoEvents
If DCount("*", "MsysObjects", "[Name]='tblFTPFileList'") = 1 Then DoCmd.DeleteObject acTable, "tblFTPFileList"
Debug.Print sLocalFLD & "\FileList.txt"
DoCmd.TransferText acImportFixed, "FileList Import Specification", "tblFTPFileList", sLocalFLD & "\FileList.txt", False
Exit_Here:
GetFtpFolderFileList = GetFileText(sScrFile)
DoCmd.Hourglass False
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "E R R O R"
Resume Exit_Here
End Function