1752796 Members
5668 Online
108789 Solutions
New Discussion юеВ

sftp in a batch

 
SOLVED
Go to solution
Gyankr
Frequent Advisor

sftp in a batch

Hi,

I was using ftp with the here-document,however i have to replace ftp with sftp.I am using a batch file for sftp but the problem is i am not able to interpret the shell variables in the batch file.Any ideas how to go about?

Regards,
Gyan
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: sftp in a batch

Hi Gyan:

Why not create a here-document on-the-fly and remove it afterwards. Something like:

# cat ./mysftp
#!/usr/bin/sh
typeset SRCFILE=/tmp/xxx
typeset DSTFILE=/tmp/yyy
typeset MYBATCH=/var/tmp/mybatch.$$
typeset MYUSER=theuser
typeset MYHOST=thehost

trap 'rm ${MYBATCH}' EXIT

(
cat <put -P ${SRCFILE} ${DSTFILE}
EOF
) > ${MYBATCH}

sftp -b ${MYBATCH} ${MYUSER}\@${MYHOST}
exit

...when the script exits, the 'trap' runs and removes the ${MYBATCH} file created. Variable substitution occurs when the here-document is built. Note that the running pid of the process is used to name the temporary here-document (${MYBATCH}) thereby avoiding name collisions.

Regards!

...JRF...
Gyankr
Frequent Advisor

Re: sftp in a batch

Thanks for your suggestion James,i will try it out.

Regards,
Gyan