HP3000-L Archives

March 2012, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Robert Mills <[log in to unmask]>
Reply To:
Robert Mills <[log in to unmask]>
Date:
Thu, 8 Mar 2012 10:32:12 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (223 lines)
donna said

 "Enough of us at this point are "multi-lingual" so you can probably ask
  questions here too. At least you know we're polite :-)"

The following is the posting I sent to the 9000-L on 28th Feb. The response (or lack of) I received from it resulted in my 'HP-UX' posting to this list and the subsequent reply by donna (see quote above). Please note that these functions have been in production (after thorough testing) for a week and have not yet displayed any problems.

------------------------------------------------------------

Subject: Critique invited on these functions.

Environment: HP-UX B.10.20 & /usr/bin/ksh (filedate 28/08/1997)

I originally wrote some ksh scripts for calling ftp that were based on command files I had written for the HPe3000. Problem is that they did not work the way I intended (had problems (different) whether I use the dot command or not).

Decided that as there is more than one way to 'skin a cat' (sorry Connie) that I'd rewrite them as ksh functions.

Is the following a reasonable way to do it or am I barking up the wrong tree?

Note: The SCRIPT_NAME variable is defined in all scripts that will be using these functions.

# ==============================================================================
# ksh functions for FTP.
# ------------------------------------------------------------------------------
# When an ftp error is detected these functions will:
#   1) display an error message,
#   2) list the contents of the file pointed to by the elog parameter,
#   3) terminate the calling script with an exit status of 1.
# ==============================================================================

# ------------------------------------------------------------------------------
# Function    : ftp_listfiles
# Description : Write a list of files residing on a remote system that meet the
#               selection criteria into a named file.
# Syntax      : ftp_listfiles <host> <user> <pass> <rdir> <fset> <list> <elog>
# Parameters  : host - IP Address or DNS name of the remote system.
#               user - FTP account name.
#               pass - FTP account password.
#               rdir - Directory holding files to be listed OR . (dot).
#               fset - Fileset (quoted) to match against OR * (asterix for all).
#               list - Name of file to contain the filelist.
#               elog - Name of file to be used for ftp error detection.
# Return Code : 0 - Action successful - Files found.
#               1 - Action successful - No files found.
#-------------------------------------------------------------------------------

function ftp_listfiles
  {
  typeset FTP_STATUS
  ftp -n -i -v ${1} << __! >${7} 2>&1
  user ${2} ${3}
  cd ${4}
  mls ${5} ${6}
  quit
__!
  FTP_STATUS=$(cat ${7} | grep 550 | wc -l)
  if [ ${FTP_STATUS} != "0" ]; then
    return 1
  fi
  FTP_STATUS=$(cat ${7} | grep 226 | wc -l)
  if [ ${FTP_STATUS} != "0" ]; then
    return 0
  fi
  echo -------------------------------------------------------------------------
  echo FATAL ERROR detected by function ftp_listfiles in ${SCRIPT_NAME}.
  cat ${7}
  echo -------------------------------------------------------------------------
  exit 1
  }

# ------------------------------------------------------------------------------
# Function    : ftp_getfile
# Description : Download the specified file from the remote system to the
#               current directory.
# Syntax      : ftp_getfile <host> <user> <pass> <rdir> <file> <elog>
# Parameters  : host - IP Address or DNS name of the remote system.
#               user - FTP account name.
#               pass - FTP account password.
#               rdir - Directory holding file to be downloaded OR . (dot).
#               file - Name of file to be downloaded.
#               elog - Name of file to be used for ftp error detection.
# Return Code : 0 - Action successful.
#-------------------------------------------------------------------------------

function ftp_getfile
  {
  typeset FTP_STATUS
  ftp -n -i -v ${1} << __! >${6} 2>&1
  user ${2} ${3}
  cd ${4}
  get ${5}
  quit
__!
  FTP_STATUS=$(cat ${6} | grep 226 | wc -l)
  if [ ${FTP_STATUS} != "0" ]; then
    return 0
  fi
  echo -------------------------------------------------------------------------
  echo FATAL ERROR detected by function ftp_getfile in ${SCRIPT_NAME}.
  cat ${6}
  echo -------------------------------------------------------------------------
  exit 1
  }

# ------------------------------------------------------------------------------
# Function    : ftp_putfile
# Description : Upload the specified file to the remote system from the
#               current directory.
# Syntax      : ftp_putfile <host> <user> <pass> <rdir> <file> <elog>
# Parameters  : host - IP Address or DNS name of the remote system.
#               user - FTP account name.
#               pass - FTP account password.
#               rdir - Directory where file to be uploaded to OR . (dot).
#               file - Name of file to be uploaded.
#               elog - Name of file to be used for ftp error detection.
# Return Code : 0 - Action successful.
#-------------------------------------------------------------------------------

function ftp_putfile
  {
  typeset FTP_STATUS
  ftp -n -i -v ${1} << __! >${6} 2>&1
  user ${2} ${3}
  cd ${4}
  put ${5} $(basename ${5})
  quit
__!
  FTP_STATUS=$(cat ${6} | grep 226 | wc -l)
  if [ ${FTP_STATUS} != "0" ]; then
    return 0
  fi
  echo -------------------------------------------------------------------------
  echo FATAL ERROR detected by function ftp_putfile in ${SCRIPT_NAME}.
  cat ${6}
  echo -------------------------------------------------------------------------
  exit 1
  }

# ------------------------------------------------------------------------------
# Function    : ftp_deletefile
# Description : Delete the specified file from the remote system.
# Syntax      : ftp_deletefile <host> <user> <pass> <rdir> <file> <elog>
# Parameters  : host - IP Address or DNS name of the remote system.
#               user - FTP account name.
#               pass - FTP account password.
#               rdir - Directory holding file to be deleted OR . (dot).
#               file - Name of file to be deleted.
#               elog - Name of file to be used for ftp error detection.
# Return Code : 0 - Action successful.
#-------------------------------------------------------------------------------

function ftp_deletefile
  {
  typeset FTP_STATUS
  ftp -n -i -v ${1} << __! >${6} 2>&1
  user ${2} ${3}
  cd ${4}
  delete ${5}
  quit
__!
  FTP_STATUS=$(cat ${6} | grep 250 | wc -l)
  if [ ${FTP_STATUS} != "0" ]; then
    return 0
  fi
  echo -------------------------------------------------------------------------
  echo FATAL ERROR detected by function ftp_deletefile in ${SCRIPT_NAME}.
  cat ${6}
  echo -------------------------------------------------------------------------
  exit 1
  }

# ==============================================================================
# End of ksh functions for FTP.
# ==============================================================================

------------------------------------------------------------

regards,

Robert W.Mills

(apologies for the size of the following company added signature)





_________________________________________________________
Disclaimer: This email transmission is privileged, confidential and intended solely for the person or 
organisation to whom it is addressed. If you are not the intended recipient, you must not copy, forward, 
distribute or disseminate the information, or take any action in reliance of it. Any views expressed 
in this message are those of the individual sender, except where the sender specifically states them 
to be the views of Forth Ports Limited. If you have received this message in error please notify 
Forth Ports Limited immediately by email to [log in to unmask] , and delete the message from 
your computer. All messages passing through this gateway are checked for viruses but we strongly 
recommend that you check for viruses using your own virus scanner as Forth Ports Limited will not 
take responsibility for any damage caused as a result of virus infection. Also, as Internet Communications 
are capable of data corruption, it may be inappropriate to rely on advice contained in an e-mail without 
obtaining written confirmation of it, and Forth Ports Limited takes no responsibility for changes 
made to this message after it was sent. The expression "Forth Ports Limited" for the purposes of 
this disclaimer includes all Forth Ports group and associated companies.   

Forth Ports Registered Offices 
Forth Ports Limited 
Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 134741 
Port of Tilbury London Limited, Registered Office: Leslie Ford House, Tilbury Freeport, Tilbury, Essex, RM18 7EH, Registered in England No 2659118 
Port of Dundee Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 155442 
Forth Estuary Towage Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 76746 
Forth Properties Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 124730 
Forth Property Developments Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 223863 
Forth Property Holdings Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 223868 
Forth Property Investments Limited, Registered Office: 1 Prince of Wales Dock, Edinburgh, EH6 7DX, Registered in Scotland No 102967 
Nordic Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 5396187 
Nordic Holdings Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 3118969 
Nordic Recycling (Lincoln) Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 06232146 
Nordic Recycling Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 2963790 
Nordic Forest Terminals Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 03112560 
Nordic Data Management Limited, Leslie Ford House, Tilbury Freeport, Essex RM18 7EH Registered in England No 3033517
Tilbury Container Services Limited, Northfleet Hope House, Site 41, Tilbury Freeport, Tilbury Essex, RM18 7HX, Registered in England No 01249844 

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2