Needed SFTP script from windows to UNIX server and from UNIX to windows server(reverse SFTP)

hi guys,
i need a script to sftp the file from windows to unix server ....(before that i have to check whether the file exists in the windows server or not

and again i have to reverse sftp the files from unix to windows server.....

regards,
Vasa Saikumar.

Well, an ftp script is far more complex than a scp.

SCP...? i didnt get u....

can u please help me on this...? i need ftp(s) secured transfer -->sftp script how can i do it...?

---------- Post updated at 12:07 PM ---------- Previous update was at 11:32 AM ----------

Hi RudiC,
actually i dnt have idea on this SFTP

wat i did is

i had the windows remote path and unix path
so at first i checked for the existing file in the widows server using if statement...

after that i dnt have any idea on this SFTP i googled it but i dnt get any exact solution for this thing... i know that i did nothing ... but i have no idea on how to kick start this.....
i had something on my mind like this...

sftp ${REMOTE_USER}@${REMOTE_MACHINE} <<EOF
cd ${REMOTE_DIR}
if [[ -f "$REMOTE_DIR"/"$FILE_NAME_TO_CHECK" ]]; then     
    get *

how to move the get files to unix server....

U can use winscp to transfer files from windows to Unix

But i had a requirement of writing the script for SFTP... is it possible..??i want to run the script as its my requirement

Okay first tell me are able to access the remote server? ???

yes.. iam able to access the remote server....

Whoever specified that requirement needs to learn how to specify REQUIREMENTS and not solutions.

Your REQUIREMENT is to move files from server to server.

SFTP is just ONE possible solution. One that's a lot harder to implement than scp or rsync.

Okay.Then u have written some code that is fine just give file name after get keyword...so that it will pull the file from windows. ..

---------- Post updated at 05:52 PM ---------- Previous update was at 05:51 PM ----------

Before that try to check u are able to login into mentioned remote directory

i have to get the same to my unix server of local path how to do that after get command do i need to specify anthing..?

There are ways to do it,
If you company got money, there is something called IP Switch - File_transfer, WS_FTP Server .

If you want to go freebee, install cygwin on your windows machine (install ssh, crontab).
Do a ssh-key exchange, write a script and you are all done.

Okay specify remote file name next to get.....so that it will download the file from your remote server i.e from your windows server

As you want to run the script interactionless, you have to know the remotedir/filename, so it would be pointless to check its existence first - it's there or not. Why not get it and check success/failure?
Try

sftp  ${remoteuser}@${host} <<EOF 2>&1 >/dev/null | awk 'NR>1 {exit 1}'
get ${remotedir}/${filename}
EOF
echo $?

The awk piece will make sure the right exit code will be issued.

EDIT: The sftp ":" form will even simplify that:

sftp ${remoteuser}@${host}:${remotedir}/${filename} && echo "found" || echo "missing"

Very old ftp ran on tcp ports 21, 20 and high ports unsecured only by a password sent in the clear. It had an arcane command set, somewhat like a severly truncated shell.

ssh runs on a different tcp port/server, 22 by default, is secure and can be set up with PPK trust so no password is needed, which supports secure scripts. It is a secure tcp socket with apps that allow remote shell, tcp tunnels or file copy.

sftp is a wrapper for ssh that speaks ftp. It is for people who want to keep using an ftp script already written, not you.

scp/winscp is another wrapper for ssh, more like the rcp and cp commands. For Push you just:

scp path_here user@there:path_there

or for Pull:

scp user@there:path_there path_here