PDA

View Full Version : Using VBA with FTP sessions in DOS



ajetrumpet
11-02-2009, 12:23 PM
hello all,

There is a problem I can't get my head around. I have this code for example:
Dim vPath As String
Dim vFTPServ As String
Dim fNum As Long

vPath = "C:"
vFTPServ = "domain.com"
fNum = FreeFile()

Open vPath & "\FtpComm.txt" For Output As #fNum
Print #1, "USER myUN" ' your login
Print #1, "pass" ' your password
Print #1, "dir " & Me.namefield & " c:\test.txt"
Print #1, "close"
Print #1, "quit"
Close

Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbHide
i am doing this everytime I want to view the contents of the TEST text file. my question is, is there a way that I can leave the FTP session open, and keep printing lines in the FTPCOMM file and keep executing DOS commands one at a time this way instead of opening and closing the connection each time?

I am getting a huge delay in updates when I run this procedure seperately evertime I want to update my interface with the DOS output, so if I can leave the session open I think I can completely eliminate the time I have to wait! I am using VBA with Office 2003 and windows vista. thanks all!

Movian
11-03-2009, 10:42 AM
is there a reason that you are using a batch file to do this rather than implementing WinHTTP.WinHTTPrequest.5
??

That way you don't have to shunt out to an external file, this might improve performance...

i utilize this to access a php script on a site that i created that acts as an interface between my database and a mysql database.

here is a snippet from my system. Hopefully you can alter it to suite your needs. I have used variations of this to download files and even send data but you will need to research and make alterations

Public Function CheckOnlineLicense(Display As Boolean, ProductKey As String)
Dim SendID As String, response As String
Dim var As Variant
Dim sVer As String, sCust As String
Dim mydb As DAO.Database, myrs As DAO.Recordset, License As DAO.Recordset
Set mydb = CurrentDb()
Set myrs = mydb.OpenRecordset("Settings")
Set License = mydb.OpenRecordset("tblLicenseCodes")

sVer = CStr(myrs.Fields("Version"))
If myrs.Fields("Custom") = True Then
sCust = "Y"
Else
sCust = "N"
End If
If Not ProductKey = "" Then
SendID = UCase(ProductKey)
Else
If Not IsNull(myrs.Fields("InstallID")) Then
SendID = UCase(myrs.Fields("InstallID"))
End If
End If

On Error Resume Next
Set mycon = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set mycon = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0

If Not IsNull(SendID) And Not UCase(SendID) = UCase("Product Key Here") Then

'Connection string to send
'MsgBox UCase(SendID) & " " & sVer & " " & sCust
mycon.Open "GET", "Your URL HERE!!!?GetText=" & UCase(SendID) & "&Ver=" & sVer & "&Cust=" & sCust
On Error Resume Next
mycon.send
If Err.Number = -2147012889 Then
MsgBox "Software requires an internet connection to authenticate with _
the license server once every two weeks. Unfortunatly it apears this computer is not currently connected to the internet. Please connect _
to the internet and try again", vbCritical, "No Internet Connection"
If Display = False Then
DoCmd.Quit acQuitSaveNone
Else
Exit Function
End If
End If
On Error GoTo 0
mycon.WaitForResponse
response = mycon.responsetext

License.Close
myrs.Close
Set mycon = Nothing
Set License = Nothing
Set myrs = Nothing
End Function