Make your own free website on Tripod.com
-->

kshWeb mkdlbat.sh
Shell Script

 

kshWeb Home | ksh Applications, Tools, Utilities | Obtain Korn Shell | Shell News Groups | Publications | Links
Korn Shell Jobs | Tip-O-The-Day | Visitor Supplied Scripts | GuestBook | Registration and Download | MicroEMACS

FREE On-Line
Events Calendar
Business Card File
Data Entry System
FREE On-Line
Korn Shell Books Free E-mail
YourName@ UnixGuru.zzn.com
YourName@ UnixWizard.zzn.com
YourName@ MCSE.zzn.com
... and many others!!!

This script generates a DOS batch file to FTP download an entire Unix directory structure including all files.

Cut and paste the following script into a file called "mkdlbat.sh" on your system. Or click on mkdlbat.sh to download a file containing the function.

#!/bin/ksh
#############################################################
# Program:	mkdlbat.sh
#               Copyright 1999
#
# Description:	The purpose of this program is to generate a 
#		DOS batch file to FTP download an entire 
#		directory structure from a Unix machine.
#
# Author:	Dana French (dfrench@mtxia.com)
#		 
#		(405) 936-2342
#
# Date:		12/21/1999
#
#############################################################
# Modifications:
#
# 12/21/1999	Version: 1.0
#		Original Code
################################################################

if [[ "_${1}" = "_" ]] || [[ "_${2}" = "_" ]]
then

print ""

[[ "_${1}" = "_" ]] && print "ERROR: Directory parameter is blank"
[[ "_${2}" = "_" ]] && print "ERROR: DOS Directory parameter is blank"

print "
The purpose of this program is to generate a DOS batch file to
ftp download an entire directory structure from a Unix site.

SYNTAX: mkdlbat.sh UnixDir DosDir
  where
	UnixDir	= Top level Unix directory to begin download 
	DosDir	= Dos directory in which to build downloaded 
		  Unix directory structure
"
exit
fi

print "
@echo off
REM ****************************************************************
REM ****    Dana French (dfrench@mtxia.com)
REM ****    Copyright 1999
REM ****    
REM ****    This batch file was automatically generated by the
REM ****    program \"${0}\" on the machine
REM ****    `uname -n` at `date`.
REM ****    
REM ****    This batch file is designed to FTP download an entire
REM ****    directory structure beginning in the Unix directory:
REM ****    \"${1}\"
REM ****    and downloading it to the DOS directory:
REM ****    \"${2}\"
REM ****************************************************************

if \"_%1\" == \"_\" goto ERROR1
if \"_%2\" == \"_\" goto ERROR2
if \"_%3\" == \"_\" goto ERROR3
"

find "${1}" -type d -print | while read DIR
do
	DOSDIR=`echo "${DIR}" | sed -e "s|${1}||g"`
	print "mkdir \"${2}${DOSDIR}\"" | sed -e "s|/|\\\|g"
done

print ""
print "echo open %1 > ftp.in"
print "echo user %2 %3 >> ftp.in"
print "echo binary >> ftp.in"
print "echo prompt >> ftp.in"
print "echo hash >> ftp.in"

find "${1}" -type d -print | while read DIR
do
	DOSDIR=`echo "${DIR}" | sed -e "s|${1}||g"`
	print ""
	print "echo cd \"${DIR}\" >> ftp.in"
	print "echo pwd >> ftp.in"
	print "echo lcd \"${2}${DOSDIR}\" >> ftp.in"
	cd "${DIR}"
	print "echo ascii >> ftp.in"
	ls -1aF | egrep "^\.|\.txt|\.htm|\.html|\.shtml" | grep -v "/$" | grep -v "^$" | sed -e "s|^|echo get \"|g;s|$|\" >> ftp.in|g"
	print "echo binary >> ftp.in"
	ls -1aF | grep -v "^\." | grep -v "\.txt$" | grep -v "\.html$" | grep -v "\.htm$" | grep -v "\.shtml$" | grep -v "/" | grep -v "^$" | sed -e "s|^|echo get \"|g;s|$|\" >> ftp.in|g"
done

print "
echo quit >> ftp.in

ftp -n < ftp.in
"

print "
goto ENDIT
:ERROR1
echo.
echo ERROR: FTP Hostname not specified
if \"_%2\" == \"_\" goto ERROR2
if \"_%3\" == \"_\" goto ERROR3
goto SYNTAX

:ERROR2
echo ERROR: User ID not specified
if \"_%3\" == \"_\" goto ERROR3
goto SYNTAX

:ERROR3
echo ERROR: Password not specified
goto SYNTAX

:SYNTAX
echo.
echo SYNTAX: %0 FTPhost UserID password
echo.
echo FTPhost = Name of the machine from which to FTP files
echo UserID = User ID to use to login to the FTP host machine
echo password = password associated with the User ID
echo.
goto ENDIT

:ENDIT
"

kshWeb Home | ksh Applications, Tools, Utilities | Obtain Korn Shell | Shell News Groups | Publications | Links
Korn Shell Jobs | Tip-O-The-Day | Visitor Supplied Scripts | GuestBook | Registration and Download | MicroEMACS

FREE On-Line
Events Calendar
Business Card File
Data Entry System
FREE On-Line
Korn Shell Books Free E-mail
YourName@ UnixGuru.zzn.com
YourName@ UnixWizard.zzn.com
YourName@ MCSE.zzn.com
... and many others!!!

 

For Information regarding this page, contact Dana French ( dfrench@mtxia.com )