Solved

Transfer a file to AS400

Posted on 2003-12-05
9
905 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
ID: 9883137
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
ID: 9883228
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
ID: 9883325
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
ID: 9883363
roberto_miguel,
    Take a look at this question

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

Dang123

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:roberto_miguel
ID: 9883371
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
ID: 9883459
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
ID: 9883957
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
ID: 9883977


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
ID: 9884151
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 51
Change the path of the data source in my Excel pivot table with macro 4 34
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 47
vbModal 12 34
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

23 Experts available now in Live!

Get 1:1 Help Now