Udostępnij za pośrednictwem


File Transfer ActiveX for Host files

 

Here is a sample to Transfer files to/from Host using file Transfer ActiveX control that ships with " Microsoft Host Integration Server" :

its needs reference to MSEIGFTLib.dll from C:\Program Files\Microsoft Host Integration Server\system\MSEIGFTLib.dll

sample HCD:  

[Stats]
CreatedOn=04/23/07 17:45:17
[Files]
USERID.JCLLIB(DTSDATA)=1
[USERID.JCLLIB(DTSDATA)]
UseForFileTransfer=1
DelimiterField=
DelimiterRecord=
TextQualifier=
FileCreationType=1
KeyPosition=0
KeyLength=0
KeySort=A
Col1=0;Col 1;Col 1;0;0;80;CHAR;CHAR;N;37; ;N;

Program in c#:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using MSEIGFTLib;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        private static bool transfercomplete;
  private static bool error;
  private static string errormessage;
  private static int errorcode;
  private static bool cancel;
  private static short ipercentdone;
  EIGFileTransferCtl FileTransfer = new EIGFileTransferCtl();
  eigConnectionStateEnum[] ConnState = new eigConnectionStateEnum[5];
  eigConnectionStateEnum[] CheckState = new eigConnectionStateEnum[5];
  int intX;
  private bool transferprogress;

  static void Main(string[] args)
        {
            Program p = new Program();
            p.TransferCreateFTTEST();

        }

        public void TransferCreateFTTEST()
  {

   try
   {
    FileTransfer = null;
    FileTransfer = new EIGFileTransferCtl();
   
    FileTransfer.TransferComplete += new _IEIGFileTransferCtlEvents_TransferCompleteEventHandler(FileTransfer_TransferComplete);
    FileTransfer.ReportError += new _IEIGFileTransferCtlEvents_ReportErrorEventHandler(FileTransfer_ReportError);
    FileTransfer.TransferProgress += new _IEIGFileTransferCtlEvents_TransferProgressEventHandler(FileTransfer_TransferProgress);

    cancel = false;
    transfercomplete = false;
    error = false;
   
                // connection parameters
                FileTransfer.CCSID = 37;
                FileTransfer.UserID = "USERID";
                FileTransfer.Password = "******";
                FileTransfer.PCCodePage = 437;
                FileTransfer.RDBName = "TEST";
                FileTransfer.LocalLU = "";
                FileTransfer.RemoteLU = "";
                FileTransfer.ModeName = "";
                FileTransfer.ConnectionType = eigConnectionTypeEnum.eigConnTypeAPPC;
         
     if (FileTransfer.ConnectionState == eigConnectionStateEnum.eigConnStateIdle)
     FileTransfer.Connect();

     FileTransfer.CreateIfNonExisting = eigAnswerYesNoEnum.eigAnswerYes;
     FileTransfer.AppendToEnd = eigAnswerYesNoEnum.eigAnswerNo;
     FileTransfer.OverwriteHostFile = eigAnswerYesNoEnum.eigAnswerYes;
     string hostpath = null;
     hostpath = "USERID.JCLLIB(DTSDATA)";

     error = false;
     FileTransfer.GetFile("C:\\DTSDATA.TXT", hostpath);
     while (transfercomplete == false && error != true) ;
     if (transfercomplete != true)
         System.Console.WriteLine(" error " + errormessage + " " + errorcode );

                   if (error == true)

                        System.Console.WriteLine(" error" + errormessage + " " + errorcode);

     if (transfercomplete == true)
    
    FileTransfer.Disconnect();

   }
   catch (Exception e)
   {
                System.Console.WriteLine(" error" +  e.Message);
   }
   finally
   {
    if (FileTransfer.ConnectionState == eigConnectionStateEnum.eigConnStateConnected)
     FileTransfer.Disconnect();
   }
  }

        void FileTransfer_TransferComplete()
        {
            transfercomplete = true;
        }

        void FileTransfer_ReportError(int hr, string Text)
        {
            errorcode = 0;
            errormessage = "";
            error = true;
            errorcode = hr;
            errormessage = Text;

        }

        void FileTransfer_TransferProgress(short PercentageDone)
        {
            if (cancel == true)
            {
                FileTransfer.Cancel();
                ipercentdone = PercentageDone;
            }
            else
            {
                ipercentdone = PercentageDone;
                transferprogress = true;
            }
            transferprogress = true;
        }

    }
}