garyilm
asked on
Access FTP bat file
I have this function that only works if I click the generated bat file. When it runs from access it does not work. In fact any batch file that I try will just open and close
Function FTP_Data()
'========================= ========== ========== ========== ========== ========
'FTP from Microsoft Access
'by Matthew V Carmichael
'Craetes FTP Batch File, FTP command file (txt)
'Default directory location of files to upload/download is
'the same location as the mdb file that contains this module.
'========================= ========== ========== ========== ========== ========'
On Error GoTo Err_Trap
Dim pFile As Long
Dim strPath As String
Dim strFileName As String
Dim ftpServer As String
Dim strUserName As String
Dim strPassword As String
'Path and Name of file to FTP
strPath = "\"
strFileName = "somefile.TXT" 'Name of file to download
'FTP Server Settings
ftpServer = "ftp.xxxx.com"
strUserName = "xxx"
strPassword = "xxx"
'Create text file containing FTP commands
pFile = FreeFile
Open strPath & "FTP_cmd3.txt" For Output As pFile
Print #pFile, "user"
Print #pFile, strUserName
Print #pFile, strPassword
Print #pFile, "bi"
Print #pFile, "Get " & strFileName
Print #pFile, "quit"
Close pFile
'Create batch file to execute FTP
pFile = FreeFile
Open strPath & "FTP_Run3.bat" For Output As pFile
Print #pFile, "ftp -s:" & "FTP_cmd3.txt " & ftpServer
Print #pFile, "Pause"
Close pFile
'Execute FTP command
Shell strPath & "FTP_Run3.bat", 1
Err_Trap_Exit:
Exit Function
Err_Trap:
MsgBox Err.Number & " - " & Err.Description
Resume Err_Trap_Exit
End Function
Function FTP_Data()
'=========================
'FTP from Microsoft Access
'by Matthew V Carmichael
'Craetes FTP Batch File, FTP command file (txt)
'Default directory location of files to upload/download is
'the same location as the mdb file that contains this module.
'=========================
On Error GoTo Err_Trap
Dim pFile As Long
Dim strPath As String
Dim strFileName As String
Dim ftpServer As String
Dim strUserName As String
Dim strPassword As String
'Path and Name of file to FTP
strPath = "\"
strFileName = "somefile.TXT" 'Name of file to download
'FTP Server Settings
ftpServer = "ftp.xxxx.com"
strUserName = "xxx"
strPassword = "xxx"
'Create text file containing FTP commands
pFile = FreeFile
Open strPath & "FTP_cmd3.txt" For Output As pFile
Print #pFile, "user"
Print #pFile, strUserName
Print #pFile, strPassword
Print #pFile, "bi"
Print #pFile, "Get " & strFileName
Print #pFile, "quit"
Close pFile
'Create batch file to execute FTP
pFile = FreeFile
Open strPath & "FTP_Run3.bat" For Output As pFile
Print #pFile, "ftp -s:" & "FTP_cmd3.txt " & ftpServer
Print #pFile, "Pause"
Close pFile
'Execute FTP command
Shell strPath & "FTP_Run3.bat", 1
Err_Trap_Exit:
Exit Function
Err_Trap:
MsgBox Err.Number & " - " & Err.Description
Resume Err_Trap_Exit
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER