Sftp some files from windows server to UNIX server | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Sftp some files from windows server to UNIX server

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-25-2013
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

hi

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




Code:
#! /bin/ksh

TARGET_DIR=<path of target directory>
FILE_NAME_TO_CHECK=<file_name>
REMOTE_USER=<user_name>
REMOTE_MACHINE=<windows server name>
REMOTE_DIR=<path of windows directory>

cd ${TARGET_DIR}

sftp ${REMOTE_USER}@${REMOTE_MACHINE} <<EOF
cd ${REMOTE_DIR}
if [[ -f "$REMOTE_DIR"/"$FILE_NAME_TO_CHECK" ]]; then     
    get *                          # downloading all the files
    mv * <path of the r_dir2>             
else
    echo "$FILE_NAM the E_TO_CHECK doesn't exist so cant copy other files"
fi

--------------------------------------------------------------------------------------------------------------
# files are getting SFTPed to the unix server but

errors:
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 01:49 PM.. Reason: Please wrap commands and data with CodeTags
Sponsored Links
    #2  
Old 01-25-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 29 September 2014, 5:34 PM EDT
Location: Aachen, Germany
Posts: 4,289
Thanks: 73
Thanked 1,033 Times in 979 Posts
What about reading the man stfp page? No if , no else , no mv , but:
Quote:
NAME
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:26 AM
Help with Unix shell script to copy files from Unix server to Windows server shankar1dada Shell Programming and Scripting 3 08-18-2011 06:17 PM
Error copying files from Unix (Solaris10) to Windows Server 2003 using scp/sftp ajaykumarb Shell Programming and Scripting 0 07-21-2010 08:44 AM
FTPing files from unix server to windows server venkatesht Shell Programming and Scripting 1 04-28-2009 09:54 AM
SFTP from windows E:/ to unix server pranavagarwal Shell Programming and Scripting 12 11-28-2007 09:58 AM



All times are GMT -4. The time now is 01:55 AM.