Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Sftp some files from windows server to UNIX server

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 01-25-2013   -   Original Discussion by vinit raj
vinit raj vinit raj is offline
Registered User
Join Date: Jan 2013
Last Activity: 13 May 2014, 12:55 PM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Sftp some files from windows server to UNIX server


i need to transfer some files from windows server to unix server using SFTP. but before transferring the files, i need to check the
existence of a particular file in the remote directory (say r_dir1). if the file is present, then SFTP all the files.
after SFTPing the files from the remote directory (r_dir1) to unix directory, i need to move the files from remote directory (r_dir1)
to some other remote directory (say dir2) in the same windows server only.

i am using the following code

#! /bin/ksh

TARGET_DIR=<path of target directory>
REMOTE_MACHINE=<windows server name>
REMOTE_DIR=<path of windows directory>


if [[ -f "$REMOTE_DIR"/"$FILE_NAME_TO_CHECK" ]]; then     
    get *                          # downloading all the files
    mv * <path of the r_dir2>             
    echo "$FILE_NAM the E_TO_CHECK doesn't exist so cant copy other files"

# files are getting SFTPed to the unix server but

1:- showing "if" and "else" statements as invalid commands
2:- showing "mv" command as invalid

please, some body provide me a solution.. i need it urgently

Last edited by joeyg; 01-25-2013 at 02:49 PM.. Reason: Please wrap commands and data with CodeTags
Sponsored Links
Old Unix and Linux 01-25-2013   -   Original Discussion by vinit raj
RudiC RudiC is online now Forum Staff  
Join Date: Jul 2012
Last Activity: 22 November 2017, 5:52 AM EST
Location: Aachen, Germany
Posts: 11,643
Thanks: 320
Thanked 3,618 Times in 3,323 Posts
What about reading the man stfp page? No if, no else, no mv, but:
sftp — secure file transfer program
rename oldpath newpath
Rename remote file from oldpath to newpath.
So - check for existence of control file with e.g. ssh ... ls, then get and rename files with sftp.

BTW - your here document is missing its final token (EOF)
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix shell script to Copy files from one Windows server to another Windows server. SravsJaya Shell Programming and Scripting 4 10-26-2011 03:26 AM
Error copying files from Unix (Solaris10) to Windows Server 2003 using scp/sftp ajaykumarb Shell Programming and Scripting 0 07-21-2010 09:44 AM
FTPing files from unix server to windows server venkatesht Shell Programming and Scripting 1 04-28-2009 10:54 AM
SFTP from windows E:/ to unix server pranavagarwal Shell Programming and Scripting 12 11-28-2007 10:58 AM

All times are GMT -4. The time now is 06:54 AM.