I
Infocore
I have a program where my Access MDB creates a new MDB file and
exports certain into it. It then sets a database password and some
other features. The user needs to fTP this file to a designated
location. Currently we have the users opening up WS_FTP and doing the
FTP on their own, I'd like to build it into my code so after it
creates the MDB it FTPs the file for them.
I am attempting to use code that I took from previous posts but am
running into an error. Although the file is sent by FTP and I can see
it on the site, it is 0KB and when I download it and try to open it, I
get a message that states "unrecognized format". Can anyone take a
look at this code and see if they spot anything that would cause this?
Public Function UploadFTPFile(sFile As String, sSVR As String, sFLD As
String, sUID As String, sPWD As String) As String
Dim sLocalFLD As String
Dim sScrFile As String
Dim sSource As String
Dim iFile As Integer
Dim sExe As String
Const q As String * 1 = """"
DoCmd.Hourglass True
On Error GoTo Err_Handler
sLocalFLD = CurrentProject.path
' 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
sSource = q & sLocalFLD & "\" & sFile & q
sScrFile = sLocalFLD & "\upload.scr"
If Dir(sScrFile) <> "" 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, "cd " & sFLD
Print #iFile, "binary"
Print #iFile, "lcd " & q & sLocalFLD & q
Print #iFile, "put " & sSource
Print #iFile, "bye"
Close #iFile
sExe = Environ$("COMSPEC")
sExe = Left$(sExe, Len(sExe) - Len(Dir(sExe)))
sExe = sExe & "ftp.exe -s:" & q & sScrFile & q
ShellWait sExe, vbHide
DoEvents
Exit_Here:
UploadFTPFile = GetFileText(sScrFile)
DoCmd.Hourglass False
MsgBox "File sent FTP", vbOKOnly, "File Complete"
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "E R R O R"
Resume Exit_Here
End Function
exports certain into it. It then sets a database password and some
other features. The user needs to fTP this file to a designated
location. Currently we have the users opening up WS_FTP and doing the
FTP on their own, I'd like to build it into my code so after it
creates the MDB it FTPs the file for them.
I am attempting to use code that I took from previous posts but am
running into an error. Although the file is sent by FTP and I can see
it on the site, it is 0KB and when I download it and try to open it, I
get a message that states "unrecognized format". Can anyone take a
look at this code and see if they spot anything that would cause this?
Public Function UploadFTPFile(sFile As String, sSVR As String, sFLD As
String, sUID As String, sPWD As String) As String
Dim sLocalFLD As String
Dim sScrFile As String
Dim sSource As String
Dim iFile As Integer
Dim sExe As String
Const q As String * 1 = """"
DoCmd.Hourglass True
On Error GoTo Err_Handler
sLocalFLD = CurrentProject.path
' 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
sSource = q & sLocalFLD & "\" & sFile & q
sScrFile = sLocalFLD & "\upload.scr"
If Dir(sScrFile) <> "" 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, "cd " & sFLD
Print #iFile, "binary"
Print #iFile, "lcd " & q & sLocalFLD & q
Print #iFile, "put " & sSource
Print #iFile, "bye"
Close #iFile
sExe = Environ$("COMSPEC")
sExe = Left$(sExe, Len(sExe) - Len(Dir(sExe)))
sExe = sExe & "ftp.exe -s:" & q & sScrFile & q
ShellWait sExe, vbHide
DoEvents
Exit_Here:
UploadFTPFile = GetFileText(sScrFile)
DoCmd.Hourglass False
MsgBox "File sent FTP", vbOKOnly, "File Complete"
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "E R R O R"
Resume Exit_Here
End Function