Solved

Transfer a file to AS400

Posted on 2003-12-05
9
901 Views
Last Modified: 2013-12-25
Hi,

I develop an application in Visual Basic 6.0 that has to transfer a file to an AS400. The problem is the control "inet" don't send the proper information, because don't support EBCDIC format.

Any ideas? Any one knows any free activeX that support EBCDIC transfers?

(I implement another way but i don't have any notification when the file transfers ends. - throat the command line executing a batch file)
0
Comment
Question by:roberto_miguel
9 Comments
 
LVL 15

Expert Comment

by:SRigney
Comment Utility
If the file is currently Ebcdic couldn't you just transfer as a binary format with INET and have it work?
0
 

Author Comment

by:roberto_miguel
Comment Utility
SRigney

But the file is in ASCII format.

How i can tranfer as a binary file with INET?
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
inet control doesn't allow to set binary or ASCII

Use ftp command if you want
or use

wininet aPI
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
roberto_miguel,
    Take a look at this question

http://oldlook.experts-exchange.com/Programming/Q_20784672.html

Dang123

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:roberto_miguel
Comment Utility
EDDYKT

Ok, I find this to use wininet API

SAMPLE: VBFTP.EXE: Implementing FTP Using WinInet API from VB (Q175179)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q175179

And i find the method to convert ASCII to EBCDIC

HOWTO: Convert Between ASCII and EBCDIC Character Codes
http://support.microsoft.com/default.aspx?scid=kb;en-us;216399

I'm going to try this solution, convert ASCII file to EBDIC format and make a binary transfer to AS400.
I hope that is works!!
0
 

Author Comment

by:roberto_miguel
Comment Utility
Dang123


I see your answer but the http://www.vbip.com/ don't work, and the solution to make a batch file i have tried.

But the solution of batch file doesn’t work for me, because i don't have any notification of the successful transfer.

The component in vbip.com is free?
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
roberto_miguel,
    The link isn't working just now for me either, strange, I was in it yesterday, you may want to try it again later. The site has a LOT of tutorials on getting VB to communicate between machines in various ways.

    If you want, I can give you code to watch the batch file running. My program writes the batch file to create a log file which I parse to check for success.

Dang123

0
 

Author Comment

by:roberto_miguel
Comment Utility


Dang123


If is possible, please send me you code (roberto.silva@elementodigital.pt).

I will try later the www.vbip.com

Thanks
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 250 total points
Comment Utility
roberto_miguel,
    It is a large project that interacts with software from a vender. Here is the parts that are important for this discusion.

(Sub that controls the FTP from a class)

Private Sub UploadFileFTP_Work()
    '*****************************************************************************************
    '
    ' Parameters:       none
    '
    ' Global Updates:   none
    '
    ' Global Read:      No global variables should be read
    '
    ' Return:           No return value - Sub
    '
    ' Description:
    '   Control FTP transfer of extracted data to mainframe.
    '
    '*****************************************************************************************
    If Not g_blnInDesign Then On Error GoTo ErrorCode
   
    Dim hndFile         As Integer
    Dim strFTP          As String
    Dim strBAT          As String
    Dim strLOG          As String
    Dim strPath         As String
    Dim strMfName       As String
    Dim strMfPack       As String
    Dim strMfPrimary    As String
    Dim strMfSecondary  As String
   
    Dim strContents     As String
    Dim intFTPCode      As Integer
   
    Dim strErrorMessage As String
   
    m_blnError = False
    strErrorMessage = ""
   
    m_LogFile.WriteToLog "FTP file to Mainframe."
    RaiseEvent StatusUpdate("Transfer data file to mainframe.", ProcessRequest_StepStart)
   
    strMfName = "TEST.TRANS.FILE"
    strMfPack = "TPACK01"
    strMfPrimary = "5"
    strMfSecondary = "3"
   
    If Dir$(m_strDataFile) = "" Then
        ReportError "Data file does not exist on server.", , True
    End If
   
    strPath = Left$(m_strDataFile, InStrRev(m_strDataFile, "\"))
    strFTP = strPath & "PayrollFTP.FTP"
    strBAT = strPath & "PayrollFTP.BAT"
    strLOG = strPath & "PayrollFTP.LOG"
   
    hndFile = FreeFile
    Open strFTP For Output As #hndFile
    Print #hndFile, "open xxx.xxx.xxx.xxx"
    Print #hndFile, "user USERID"
    Print #hndFile, "PASSWORD"
    Print #hndFile, "DELETE '" & strMfName & "'"
    Print #hndFile, "QUOTE SITE Unit=SYSDA VOLume=" & strMfPack & " RECFM=FB LRECL=200 BLKSIZE=20000"
    Print #hndFile, "QUOTE SITE CYlinders PRImary=" & strMfPrimary & " SECondary=" & strMfSecondary
    Print #hndFile, "PUT """ & m_strDataFile & """ '" & strMfName & "'"
    Print #hndFile, "BYE"
    Close #hndFile
   
    hndFile = FreeFile
    Open strBAT For Output As #hndFile
    Print #hndFile, "ftp -n -s:""" & strFTP & """ > """ & strLOG & """"
    Close #hndFile
   
    WaitFor strBAT
   
    If Dir$(strLOG) <> "" Then
        strErrorMessage = ""
        hndFile = FreeFile
        Open strLOG For Input As #hndFile
        Do While Not EOF(hndFile)
            Line Input #hndFile, strContents
           
            m_LogFile.WriteToLog strContents
           
            intFTPCode = Val(Left$(strContents, 3))
            If (intFTPCode >= 400 And intFTPCode <= 599) _
             And (InStr(strContents, "does not exist") = 0) Then
                m_blnError = True
                strErrorMessage = strErrorMessage & "    " & strContents
            End If
        Loop
    End If
   
    Kill strFTP
    Kill strBAT
   
    RaiseEvent StatusUpdate("", ProcessRequest_StepEnd)
   
    If m_blnError Then
        ReportError Trim$(strErrorMessage)
        Exit Sub
    End If
   
    m_LogFile.WriteToLog "Transfer complete."
    RaiseEvent StatusUpdate("Transfer Complete.", ProcessRequest_ProcessEnd)
   
    Exit Sub
ErrorCode:
    Select Case Err.Number
        Case Else
            Err.Raise Err.Number, , "clsProcessRequest UploadFileFTP - " & Err.Description
    End Select
End Sub




************* basWaitFor.bas ***********************

Attribute VB_Name = "basWaitFor"
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code module containing all logic to shell to another program                 '
'   Adapted from sample code found on VBnet (www.mvps.org/vbnet)               '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private Const STILL_ACTIVE = &H103


'Constants for OpenProcess API (DesiredAccess)
Private Const PROCESS_ALL_ACCESS        As Long = &H1F0FFF  'Specifies all possible access flags for the process object.
Private Const PROCESS_CREATE_THREAD     As Long = &H2       'Enables using the process handle in the CreateRemoteThread function to create a thread in the process.
Private Const PROCESS_DUP_HANDLE        As Long = &H40      'Enables using the process handle as either the source or target process in the DuplicateHandle function to duplicate a handle.
Private Const PROCESS_QUERY_INFORMATION As Long = &H400     'Enables using the process handle in the GetExitCodeProcess and GetPriorityClass functions to read information from the process object.
Private Const PROCESS_SET_INFORMATION   As Long = &H200     'Enables using the process handle in the SetPriorityClass function to set the priority class of the process.
Private Const PROCESS_TERMINATE         As Long = &H1       'Enables using the process handle in the TerminateProcess function to terminate the process.
Private Const PROCESS_VM_OPERATION      As Long = &H8       'Enables using the process handle in the VirtualProtectEx and WriteProcessMemory functions to modify the virtual memory of the process.
Private Const PROCESS_VM_READ           As Long = &H10      'Enables using the process handle in the ReadProcessMemory function to read from the virtual memory of the process.
Private Const PROCESS_VM_WRITE          As Long = &H20      'Enables using the process handle in the WriteProcessMemory function to write to the virtual memory of the process.
Private Const SYNCHRONIZE               As Long = &H100000  'Enables using the process handle in any of the wait functions to wait for the process to terminate.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  API Declarations                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetExitCodeProcess Lib "kernel32" _
    ( _
    ByVal hProcess As Long, _
    lpExitCode As Long _
    ) As Long

Private Declare Function OpenProcess Lib "kernel32" _
    ( _
    ByVal dwDesiredAccess As Long, _
    ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long _
    ) As Long

Private Declare Sub Sleep Lib "kernel32" _
    ( _
    ByVal dwMilliseconds As Long _
    )

Private Declare Function CloseHandle Lib "kernel32" _
    ( _
    ByVal hObject As Long _
    ) As Long

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  Public Module Subs/Functions                                     '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub WaitFor( _
    ByVal strFilePath As String _
    )
   
    '*****************************************************************************************
    '
    ' Parameters:       strFilePath - command to execute program
    '
    ' Global Updates:   None
    '
    ' Global Read:      None
    '
    ' Return:           None - Sub
    '
    ' Description:
    '   Shells a process and waits for it to complete.
    '
    '*****************************************************************************************
    If Not g_blnInDesign Then On Error GoTo ErrorCode

    Dim lngProcess  As Long     'Process handle
    Dim lngReturn   As Long     'Return value from shelled program
   
    'The next line launches the process in a normal window with focus and captures process ID
    lngProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(strFilePath, vbNormalFocus))
   
    Do
        Call GetExitCodeProcess(lngProcess, lngReturn)  'Get the status of the process
        Sleep 100                                       'Sleep and DoEvents both recommended
        DoEvents
    Loop While lngReturn = STILL_ACTIVE                 'Loop while the process is active
   
    Call CloseHandle(lngProcess)                        'Close handle to free memory structures
   
    Exit Sub
ErrorCode:
    Select Case Err.Number
        Case Else
            Err.Raise Err.Number, , "(basWaitFor-WaitFor)" & Err.Description
    End Select
End Sub

Public Function StartProcess( _
    ByVal strFilePath As String _
    ) As Long
   
    '*****************************************************************************************
    '
    ' Parameters:       strFilePath - command to execute program
    '
    ' Global Updates:   None
    '
    ' Global Read:      None
    '
    ' Return:           Process ID for new process.
    '
    ' Description:
    '   Shells a process and returns process ID.
    '
    '*****************************************************************************************
    If Not g_blnInDesign Then On Error GoTo ErrorCode
   
    'The next line launches the process in a normal window with focus and captures process ID
    StartProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(strFilePath, vbNormalFocus))
   
    Exit Function
ErrorCode:
    Select Case Err.Number
        Case Else
            Err.Raise Err.Number, , "(basWaitFor-StartProcess)" & Err.Description
    End Select
End Function

Public Function CheckProcess( _
    ByVal lngProcess As Long _
    ) As Boolean
   
    '*****************************************************************************************
    '
    ' Parameters:       lngProcess - process ID to check
    '
    ' Global Updates:   None
    '
    ' Global Read:      None
    '
    ' Return:           True if the process is still running.
    '                   False if the process is finished.
    '
    ' Description:
    '   Shells a process and returns process ID.
    '
    '*****************************************************************************************
    If Not g_blnInDesign Then On Error GoTo ErrorCode
   
    Dim lngReturn   As Long                         'Return value from shelled program
   
    Call GetExitCodeProcess(lngProcess, lngReturn)  'Get the status of the process
    Sleep 100                                       'Sleep and DoEvents both recommended
    DoEvents
   
    If lngReturn = STILL_ACTIVE Then                'Test if the process is active
        CheckProcess = True
    Else
        CheckProcess = False
        Call CloseHandle(lngProcess)                'Close handle to free memory structures
    End If
   
    Exit Function
ErrorCode:
    Select Case Err.Number
        Case Else
            Err.Raise Err.Number, , "(basWaitFor-CheckProcess)" & Err.Description
    End Select
End Function

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now