Okay first and foremost we have to thinkabout how we get the login to succed if run from script. If you want to use a password take a look into expect.
Else setup passwordless ssh login with private public key pair. There are more than enough tuts on the net for this.
For the actual scripting you can pass a command to be executed at the remote machine to ssh. If you want to run multiple commands you can use either a script on the remote machine or use ; to tell the shell that this commands end. After the ; comes another command to be run.
So the script could look like this
Code:
#!/bin/bash
ssh sshusername@sshserver "sftp-binary sftpuser@sftpserver remote_filename localfilename
scp sshusername@sshserver localfilename targetfilename
First line is a magic shebang that tells the shell which program it is to use to interpret the rest of the content.
second line connects to sshserver with the user sshusername and runs the comman sftp-binary to download the file from the sftpserver to the sshserver.
Next line uses scp to copy file from sshserver to your local machine.
Check the bash scripting guide on tldp.org to get a grip of shell scripting.