sftp

Hi,

Can you please tell me what the below command does

cat <<EOF1 > $tmp1
binary
lcd $targetDir
cd ${remoteDir}
ls
quit
EOF1

cat $tmp1
set -x
sftp6 -P 2246  -B $tmp1 --password=file://<ctl>/.gspass | tee outputfile

Actually my requirement is if the sftp succeed, then only it has to right the output other send an eroor output.

Please help me with ur suggestions.

To my knowledge FTP/SFTP if it can run will always be a success...
So if you need more, you will have to find a way of testing (not ftp command for it will be successfull...) that suits your need...

By the way, avoid cyber chat style language here

the remote server may be down at times, that time, it should not write the output of the sftp to a file, it should return error. If it is successfully connected the server, then the output should be written to a file

Code:
cat <<EOF1 > $tmp1
binary
lcd $targetDir
cd ${remoteDir}
ls
quit
EOF1

cat $tmp1
set -x

sftp6 -P 2246 -B $tmp1 --password=file://<ctl>/.gspass | tee outputfile

Now the code is writing all kind of data (either successfully connected / failed to fetch data) into the output file. It should not be the case.

Can anyone please let me know any suggestion.

Why should it not ?( what about using code tags then...)
I see nothing in your code saying not to...
Remember my first post?