#!/usr/local/bin/kermit +
;
; ibm_infoexchange
;
; Makes a secure FTP connection to IBM Info Exchange.
; Requires Kermit 95 1.1.21 or C-Kermit 8.0 or later.
;
; Authors: J. Altman, F. da Cruz, Columbia U, June 2002.
; Most recent update:
; Mon Feb 24 10:56:44 2003
;
define \%v 2.08 ; Version of this script
define host ieftpint2.services.ibm.com ; Change this to access another host.

; Unix Usage:
;   Change the first line to point to the C-Kermit 8.0 executable.
;   Give this script execute permission.  Then:
;   ibm_infoexchange [ username [ password ] ]
;
; Windows Usage:
;   k95 ibm_infoexchange  [ username [ password ] ]
;
; Or at the Kermit prompt (Windows or Unix):
;   take ibm_infoexchange  [ username [ password ] ]
;
; Include your IBM IE username as the first command-line argument to 
; this script.  If the username is not given, the script prompts you for it.
;
; If you wish, you may also include your IBM IE password as the second
; command-line argument.  If no password is given, you are prompted for it.
;
; To debug, "define debug 1" before starting the script.
;
; The default locations for the certificate and key files are shown below
; in the script.  If you put them somewhere else, change the script
; accordingly.  For further details visit:
;
;   http://www.columbia.edu/kermit/ibm_ie.html 

define badversion echo C-Kermit 8.0 or K95 1.1.21 or later required, exit 1
if LLT \v(version) 800200 badversion
if k-95 set title IBM Information Exchange
if not avail ssl exit 1 "Sorry, SSL not available"

if not defined DEBUG define DEBUG 0  ; Change to 1 to debug
if not numeric DEBUG define DEBUG 1

echo IBM INFO EXCHANGE ACCESS SCRIPT VERSION \%v

if not def \%1 {                     ; If username not given on command line..
    undef \%8                        
    asg \%9 \v(user)                 ; SET LOGIN USER value (if any)
    if def \%9 asg \%8 { [\%9]}      ; Default to show in prompt
    while not def \%1 {
	ask \%1 "IBM Info Exchange User ID\%8: "
	if not def \%1 asg \%1 \%9
    }
}

if k-95 { ; Kermit 95
    if exist \v(appdata)certs/ibm_ie_personal.pem {
	set auth ssl rsa-cert-file \v(appdata)certs/ibm_ie_personal.pem
	set auth ssl rsa-key-file \v(appdata)certs/ibm_ie_personal.pem
    } else {
	set auth ssl rsa-cert-file \v(appdata)ibm_ie_personal.pem
	set auth ssl rsa-key-file \v(appdata)ibm_ie_personal.pem
    }
    if < \v(xversion) 2000 set auth ssl verify-file \v(common)ibm_ie_ca.pem
} else {  ; C-Kermit (SAMPLE locations -- your "certs" subdirectory)
    set auth ssl rsa-cert-file \v(home)certs/ibm_ie_personal.pem
    set auth ssl rsa-key-file \v(home)certs/ibm_ie_personal.pem
    set auth ssl verify-file \v(home)certs/ibm_ie_ca.pem
}
set auth ssl verify peer-cert

if \m(debug) {
    set auth ssl verbose on
    set auth ssl debug on
    set ftp debug on
} else {
    set auth ssl verbose off
    set auth ssl debug off
    set ftp debug off
}

set file collision backup
set file incomplete auto
set file names literal
set receive pathnames off
set send pathnames off
set ftp autologin on
set ftp passive on
set ftp autoauth on
set ftp autoenc on
set ftp credential-forwarding off
set ftp dates on
set ftp filenames literal
set ftp verbose on
set ftp authtype ssl tls 
set ftp server-character-set ascii
set ftp character-set-translation off

; The following is a temporary workaround for a bug in the IBM server,
; which should be fixed as of 15 January 2003.
; Note: the Cipher name is case-sensitive.
if > \v(xversion) 1121 set auth tls cipher-list EXP1024-RC4-SHA

; To suppress certificate warnings uncomment the following command:
; set auth tls certs-ok on

; Avoid SET LOCUS prompt - force DIR, CD, etc, to act at server.
set locus remote

ftp open \m(host) ftp /noinit /user:\%1 /password:\%2
if success {
    set ftp command-protection-level private
    set ftp data-protection-level private
    echo
    echo Connected to IBM Info Exchange.
    echo "You may now give FTP client commands like DIR, CD, MGET, etc."
    echo Type "help ftp" for further information.
    echo
} else {
    echo Secure FTP Connection Failed: \v(ftp_message)
}
end
