cancel
Showing results for 
Search instead for 
Did you mean: 

Re: sftp in a batch

 
SOLVED
Go to solution
Highlighted
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
Highlighted
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...
Highlighted
Frequent Advisor

Re: sftp in a batch

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

Regards,
Gyan