shell script to transfer files from Unix to Windows

I need to write a shell script to transfer files from Unix server to windows machine. This script will be scheduled on scheduler to run at specified intervals

#!/bin/ksh
ftp -n alaska <<End-Of-Session
user sss01 sample
cd /home/sss01
lcd D:/sample
mget *.txt
bye

when I executed the above shell script. It throws error saying file location D:/sample not found.
Can somebody please help me in writing the script?

You code should contain the terminating here-document End-Of-Session

#!/bin/ksh
ftp -n alaska <<End-Of-Session
user sss01 sample
cd /home/sss01
lcd D:/sample
mget *.txt
bye
End-Of-Session

Hi Vino,

Thanks for you reply!
I added the EOF statement at the end. Now the session the coming out of ftp. but the error 'D:/Nagaraj: No such file or directory' still exists
can you please help..

Hmmm... Drop the ':' to make it D/Nagaraj

It's complaining about the "lcd" command, telling the local system (that's running the FTP script) to change directory (as opposed to changing the directory on the FTP server.)

That looks like a Windows path to me (D:\sample). But your script is calling /bin/ksh. Are you on a Windows box, a Unix box, or a Windows box with SFU or Cygwin installed?

I created also script to transfer file from UNIX to WIn.but I had to set up ftp directory in windows(IIS) so I can just put my files in that directory..

I would also love to see is it possible to use lcd command so I could change windows directory in my unix script???

It that possible??

Help
How do i issue an command via FTP to an AS400 from an unix platform? :eek:

You still haven't answered my questions... Where are you running the script (Windows or Unix)? Where is the FTP server (Windows or Unix)?

that script is on UNIX...something like a script knag mention...

and is there a way to change dir.from unix...fo change dir.where unix script transfers files...

Shouldn't the slash be of the other type. The palce where u are specifying lcd would be D:\sample. and since the script is on Unix
cd D:\sample
and
lcd /home/sss01

OK I am posting whole script...

on UNIX:
ftpscript:

#!/bin/ksh
#Usage example: ftpscript readme.txt /pub/dir1/readme.txt
localFile=$1
remoteFile=$2

ftplog=loglog.log
echo "$(date "+%H:%M:%S") - Attempt to FTP $1 to $2" > $ftplog

# do the FTP put

ftp -i -n <<EOF >> $ftplog
open <hereIPaddress>
user someuser somepass
put $localFile $remoteFile
ls $remoteFile
quit
EOF

./ftpscript localfile.txt
so by entering IP of my windows machine and execution of this script file goes to windows...and this works..but file goes to my directory I specified in IIS I was wondering can I tell in UNIX script where to place file when it is transfer from U. to W.??

Thanks for answers..

I think it "lcd directory" name

I'm trying to find a way to subit a quote command from a unix ftp scrip to an as400. How do i do this?

kang tried with lcd command ...it did not worked...

This script run via autosys

#
HOST="machine"
IDPASSWORD="maichine.in"
LOCALDIR="lcd /xxxx/temp/"
EMAILNAMES="person's e-mail address"
LOCALMACHINE="local machine"
HOSTDIR="cd /tmp/"
TRANSFERTYPE=""
TRANSFERFUNCTION="put"
CHECKNAME=""
CHMOD="chmod 775"
FILENAME1="filename.txt"
LIST=
VENDOR=""

######################################################################
dt=`date '+%Y%m%d_%H%M'`
TMPDIR=/home/autosys/FTPlog
LOGDIR=/home/autosys/FTPlog
TMPFILE1=${TMPDIR}/`basename $0`.tmp1
TMPFILE2=${TMPDIR}/`basename $0`.tmp2
ERRFILE=${LOGDIR}/${AUTO_JOB_NAME:-`basename $0`}.err
LOGFILE=${LOGDIR}/${AUTO_JOB_NAME:-`basename $0`}.log
JOBNAME=${AUTO_JOB_NAME:-`basename $0`}
############################
#initalize log files, also done in autosys job Definition with std_out_file
cat /dev/null >${LOGFILE}
cat /dev/null >${ERRFILE}
###################################
DATE=`date +%m"/"%d"/"%y`

#
#Subroutine email_msg
#Arguements $1 - Message to send in email
#Description Send message in email
email_msg()
{
MAIL_TO_SUCC="$EMAILNAMES"
print "To:$MAIL_TO_SUCC\nSubject: $1 - $JOBNAME" | /usr/lib/sendmail -t

}

#Subroutine log_msg
#Arguements $1 - Message to write in log
#Description Write message to log file
log_msg()
{
echo "`date +'%b %d %H:%M:%S '`${HOST} $0[$$]: ${1}" >> ${LOGFILE}
}

log_msg "$0 started"

#
print "$LOCALMACHINE $JOBNAME THIS IS THE DATE=$DATE" >>${LOGFILE}

echo 'BEGINNING FTP ROUTINE...'
cat /idpass/$IDPASSWORD >$HOME/.netrc 2>> ${LOGFILE}
echo "open $HOST">${LOGDIR}/t
echo "$TRANSFERTYPE">>${LOGDIR}/t
echo "$HOSTDIR">>${LOGDIR}/t
echo "$LOCALDIR">>${LOGDIR}/t
echo "ls $LIST">>${LOGDIR}/t
echo "$TRANSFERFUNCTION $FILENAME1">>${LOGDIR}/t
echo "$CHMOD $FILENAME1">>${LOGDIR}/t
echo "ls $LIST">>${LOGDIR}/t
echo "quit" >>${LOGDIR}/t
echo "bye" >>${LOGDIR}/t
echo "" >>${LOGDIR}/t
ftp -ivd < ${LOGDIR}/t >>${LOGFILE} 2>${LOGFILE}
echo 'FTP ROUTINE HAS ENDED...'
cat /dev/null>$HOME/.netrc

I have condition checks after this

results:
Connected to machine.
220 machine FTP server (Version 1.1.214.7 Thu Aug 10 09:57:38 GMT 2000) ready.
---> USER xxxxx
331 Password required for xxxx.
---> PASS XXXXXX
230 User xxxx logged in.
---> SYST
215 UNIX Type: L8
Remote system type is UNIX.
---> TYPE I
200 Type set to I.
Using binary mode to transfer files.
---> CWD /tmp/
250 CWD command successful.
Local directory now /xxxx/temp/
---> PORT xxx.xxx.xxx.xxx,188
200 PORT command successful.
---> TYPE A
200 Type set to A.
---> LIST *
150 Opening ASCII mode data connection for /usr/bin/ls.
-rwxrwxr-x 1 xxxxx xxxxx_sys 1003779 Jun 15 09:48 filename.txt
226 Transfer complete.

I wanted to register to this forum to introduce myself. My name is Joe Clark. I am a recruiter with TEKsystems in Illinois. We are a nationwide IT solutions company.

I am always looking for solid IT professionals who work in a Unix environment. Currently, I am working on a Unix to Windows migration position. I am having a difficult time finding qualified candidates. If anyone is interested, or knows of anyone who may be interested in this position, please let me know via email or telephone. My number is 847-632-9229. My email is eaclark@teksystems.com

If anyone is looking for new opportunities in the IT field, please let me know.