System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

to automate the sftp or ftp or scp download files from unix to windows

 
apple
Super Advisor

to automate the sftp or ftp or scp download files from unix to windows

Dear HPUX gurus,
would like to seek your advice. we would like to automate the downloading files from unix to windows in cron on weekly basis. i have the following doubts, would really appreciate your advice.
1. can sftp from unix to windows?
2. i want to remove the the files upon the ftp successfuly login. can we just compare the destination and source after we completed the the downloading, and if it is the same file name or count, do remove the file from source?
3. how to output this download log to textfile.

herewith is my simple script and entry in cron tab for your comments and advice.

# more autoftp.txt
!/usr/bin/ksh
ftp -v -i -d -n 120.1.1.90
user apple apple1
cd /tmp/nmon
lcd C:/Temp/perf
mput *.nmon
bye

# crotab -l
30 22 * * 5 /appl/scripts/rcp/auto_rcpfile 1>/dev/null 2>/dev/null

hope to hear from you. promise of good points.Thank You
4 REPLIES
Steven Schweda
Honored Contributor

Re: to automate the sftp or ftp or scp download files from unix to windows

> 1. can sftp from unix to windows?

Perhaps, if your Windows system runs an SFTP
server. Have you tried SFTP to your Windows
system? SCP? (SSH?)

> ftp -v -i -d -n 120.1.1.90

Have you tried FTP to your Windows system?

2. [...] can we just compare [...]

Compare how?

> [...] same file name or count [...]

Is that what's important to you, or do the
actual data matter?

> 3. how to output this download log to
> textfile.

"> textfile"? Something other than
"1>/dev/null 2>/dev/null" might save more.

> herewith is my simple script [...]

Have you tried it?

> user apple apple1

I see that security is not important.

> cd /tmp/nmon
> lcd C:/Temp/perf

Which system is the Windows system?
T G Manikandan
Honored Contributor

Re: to automate the sftp or ftp or scp download files from unix to windows

Hi apple,

this is what i would do, i would install cygwin on windows and use scp instead of sftp.

you need to add the neccessary modules like SSH while installing cygwin , so that you can place the scp script on windows and it can pull the logfiles from the server.

please let me know if you need more help.

http://www.cygwin.com/
Ganesan R
Honored Contributor

Re: to automate the sftp or ftp or scp download files from unix to windows

Hi Apple,

First decide which mode(ftp or sftp) you are going to use for file transfer. If you are going to use ftp steps are very simple.

If it is ftp these are the steps you need to follow.
We can setup a cron job on unix server to copy the files. Instead of removing the source file after copying, it is better to backup those files and compress it for future. Later on you can remove the backup compress files.

Assuming you have account called apple with password apple123 on windows server. Windows server ip is 10.15.20.100

on unix server edit the $HOME/.netrc file and put the below entry. This is to login ftp without password..

#vi $HOME/.netrc
machine 10.15.20.100 login apple passwd apple123

Create a script to automate the job

#vi /tmp/nmon/ftpjob
export LOG=/tmp/nmon/log
export ARCH=/tmp/nmon/archive/
export FIL="*.nmon"
echo " " >> ${LOG}
#------------------------------------------------------
# Check for file to transfer to windows
#------------------------------------------------------

cd /tmp/nmon
files=`ls |grep ${FIL} |wc -l`
if [ $files -gt 0 ]
then
echo "File: `ls|grep ${FIL}`" >> ${LOG}
ftp 10.15.20.100 << EOF
bin
mput ${FIL}*
bye
EOF
mv ${FIL}* ${ARCH}
else
echo "No file to windows" >> ${LOG}
exit 1
fi
exit


Put this job in cron like below..
30 22 * * 5 /tmp/nmon/ftpjob >> /tmp/nmon/ftpjob.log 2>&1
Best wishes,

Ganesh.
Ganesan R
Honored Contributor

Re: to automate the sftp or ftp or scp download files from unix to windows

Hi Apple,

If you decided to use sftp things are little different. First you need to configure password less login for the account which is going to run the script between the unix server and windows server. Script should be like this...

#-------------------------------------------------------
# Put files to Windows using sftp
#-------------------------------------------------------
LOG=/tmp/nmon/log
TODAY=`date +'%d%b%y'`
#-------------------------------------------------------
# Any files received for transfer?
#-------------------------------------------------------
fn=`ls /tmp/nmon`

if [ ${fn:-NO} = "NO" ];
then
echo "No file" >> $LOG
exit
else
echo "Files to send: $fn" >> $LOG
#-------------------------------------------------------
# Connect to windows server and put the files
#-------------------------------------------------------
sftp username@10.15.20.100 <<**
lcd /tmp/nmon
mput *.nmon
**
#-------------------------------------------------------
# Cleanup
#-------------------------------------------------------
cd
mv /tmp/nmon/$fn /tmp/nmon/archive/$fn.$TODAY
compress /tmp/nmon/$fn.$TODAY
rm /tmp/nmon/*.nmon
fi

put this script on crontab. Script will work only if password less login is configured between unix and windows server.
Best wishes,

Ganesh.