Link to home
Start Free TrialLog in
Avatar of woodan1
woodan1

asked on

vb code to run shell and then pass results to a variable in msaccess

I am trying to do authentication of a user using ftp.  I have found in the cmd line that for cmd /k ftp -s:" & strPath the code 230 = Logged in and 530 = failed.  I want to read these results and grant permission to my database based on either of these numbers.  

I need to figure out how to write the shell results to a variable or txt file.  Preferably a variable in msaccess.

    If Not IsNull(Me.PWD) And Not IsNull(Me.CDSID) Then
    '    Write to ftp.txt
        Dim strFTP As String, strPath As String
        strFTP = "open xxxxxxxx.xx.xxxxx.com" & vbCrLf & _
            "yyyyyy/" & Me.CDSID & vbCrLf & _
            Me.PWD & vbCrLf & _
            "Quit"
       
        strPath = "C:\WINDOWS\Temp\ftp.txt"
       
        Open strPath For Output As #1
        Print #1, strFTP
        Close #1

    '   Execute ftp.txt
        Shell ("cmd /k ftp -s:" & strPath)
   
    '   Write to variable
 >>>This is the part in question!!!
   
    '   Look for 230(logged in) or 530(failed)

       
    '   Delete ftp.txt
       
       
    End If

Thanks.
Dan
Avatar of niblick
niblick

'Variables' disappear when Access is closed.  Just create a table with a field and use that as your 'variable'.
nib
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or more precisely:

You must redirect the output to a file which you then open and read in.

/gustav
Re-direct works, you will need to determine what kind of a time-delay you need in order to let the FTP complete before you go looking at the output file.

and another way that once you add the code it becomes very easy to connect to a server and get results from the connection or error code ...
http://www.mvps.org/access/modules/mdl0037.htm


Steve
Avatar of woodan1

ASKER

cactus_data'
What would the line of code look like.  I'm new to shell in vb.

Shell ("cmd /k ftp -s:" & strPath & ">ftp.log") didn't work

this is the output in shell which I want stored in ftp.log:

ftp> open xxxxxxxx.xx.xxxxx.com
Connected to xxxxxxxx.xx.xxxxx.com
220 xxxxxxxx Microsoft FTP Service (Version 4.0).
User (xxxxxxxx.xx.xxxxx.com:(none)):
331 Password required for xxxxx/yyyyyy.

230-This is a Private Computer Network.
230-Unauthorized use will result in prosecution.
230 User xxxxx/yyyyyy logged in.
ftp>
ftp> Quit
221
Avatar of woodan1

ASKER

Nevermind I got it to work.  I had to put the directory path.

Shell ("cmd /k ftp -s:" & strPath & ">C:\WINDOWS\Temp\xxx.log")
Fine. Command lines can be tricky.

/gustav