SFTP error in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP error in UNIX
# 1  
Old 08-25-2016
SFTP error in UNIX

I have this code snippet:
Code:
sftp $USERNAME@$REMOTE_SERVER -omode=ascii >> $LOG_FILEPATH/$LOG_FILENAME  2>&1                                    
ls /+showall                                                                                                    
ls /+ mode=text,recfm=fb,lrecl=80,space=trk.8.1,release                                                            
##quote site file=jes
pwd                                                                                                                
lcd $LOCAL_DIRECTORY
lpwd                                                                                                            
$DIRECTION $LOCAL_FILENAME $REMOTE_FILENAME                                                                        
ls $REMOTE_FILENAME                                                                                                
cd //$REMOTE_DIRECTORY                                                                                            
ls /+mode=text,jesjobwait                                                                                        
lcd $BIN_PATH                                                                                                    
lpwd                                                                                                            
$DIRECTION $LOCAL_JOBNAME $REMOTE_JOBNAME                                                                        
ls $REMOTE_JOBNAME                                                                                                
get /+/error.log                                                                                                 
quit

and i get the following error when i execute this program:

Code:
syntax error at line 157: `end of file' unexpected

Please advise.

Thanks,
Jess

Last edited by rbatte1; 08-26-2016 at 04:20 AM.. Reason: Added CODE tags for output
# 2  
Old 08-25-2016
I do not see where you say to sftp its in batch mode for a start...
How do you expect us to tell you what is wrong giving us only partial code, when error mentions line 157?
# 3  
Old 08-25-2016
Can you reproduce that code snippet with line numbers, or at least point out where line 157 is, please?
# 4  
Old 08-25-2016
Moderator's Comments:
Mod Comment Posting "Does not work" without explanation does not help you or anyone. If a command does not work for you, please show the exact circumstances you used it, and the exact error or malfunction you received. Do not paraphrase errors, or post the text as links, images, or attachments if you can avoid it: Paste the original code and the exact message, in code tags, like [code] text [/code] or by selecting the text and using the Image button.

Thank you.

The UNIX and Linux Forums
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-25-2016
Code:
USERNAME="$1"
export USERNAME
REMOTE_SERVER="$2"
export REMOTE_SERVER
LOCAL_DIRECTORY="$3"
export LOCAL_DIRECTORY
REMOTE_DIRECTORY="$4"
export REMOTE_DIRECTORY
DIRECTION="$5"
export DIRECTION
LOCAL_FILENAME="$6"
export LOCAL_FILENAME
REMOTE_FILENAME="$7"
export REMOTE_FILENAME
LOGFILE_PATH="$8"
export LOGFILE_PATH
LOG_FILENAME="$9"
export LOG_FILENAME
BIN_PATH="$10"
export BIN_PATH
LOCAL_JOBNAME="$11"
export LOCAL_JOBNAME
REMOTE_JOBNAME="$12"
export REMOTE_JOBNAME

##Validating if all inputs were entered
echo "Entering the program `date`" 																				| tee -a $LOG_FILEPATH/$LOG_FILENAME
if [ $# -ne 12 ]
then
echo "One or more inputs to this program were not entered." 													| tee -a $LOG_FILEPATH/$LOG_FILENAME
echo "Please verify the Appworx module" 																		| tee -a $LOG_FILEPATH/$LOG_FILENAME
echo "Aborting the program on `date`"																			| tee -a $LOG_FILEPATH/$LOG_FILENAME
exit 1
else
echo "All inputs to this program have been entered" 															| tee -a $LOG_FILEPATH/$LOG_FILENAME
fi

echo "Connecting to the BLUE Mainframe with USER:$USERNAME" 													| tee -a $LOG_FILEPATH/$LOG_FILENAME
echo "Remote host is: $REMOTE_SERVER"                                                                           | tee -a $LOG_FILEPATH/$LOG_FILENAME
sftp $USERNAME@$REMOTE_SERVER -omode=ascii >> $LOG_FILEPATH/$LOG_FILENAME  2>&1                        	        
ls /+showall																									
ls /+ mode=text,recfm=fb,lrecl=80,space=trk.8.1,release															
##quote site file=jes
pwd																												
lcd $LOCAL_DIRECTORY
lpwd																											
$DIRECTION $LOCAL_FILENAME $REMOTE_FILENAME																		
ls $REMOTE_FILENAME																								
cd //$REMOTE_DIRECTORY																							
ls /+mode=text,jesjobwait																						
lcd $BIN_PATH																									
lpwd																											
$DIRECTION $LOCAL_JOBNAME $REMOTE_JOBNAME																		
ls $REMOTE_JOBNAME																								
get /+/error.log 																								
quit

echo "SFTP connection successfully exited"  																	| tee -a $LOG_FILEPATH/$LOG_FILENAME
echo "Checking the log file for errors"																			| tee -a $LOG_FILEPATH/$LOG_FILENAME

cd $LOG_FILEPATH
sftp_check=`grep -i "Aborting the program" $LOG_FILENAME | wc -l`
if [ "$sftp_check" -gt 0 ]
then
        echo '\n'
        echo "##################################"
        echo  ERROR: Please enter the input parameters correctly.
        echo  'SFTP to Blue Server failed'
        echo "##################################"
        echo `date`
        exit 1
fi

sftp_check=`grep -i "Couldn't stat remote file" $LOG_FILENAME | wc -l`
if [ "$sftp_check" -gt 0 ]
then
        echo '\n'
        echo "##################################"
        echo  ERROR: SFTP Transfer Not Completed
        echo  'SFTP to Blue Server failed'
        echo "##################################"
        echo `date`
        exit 1
fi

sftp_check=`grep -i "No such file or directory" $LOG_FILENAME | wc -l`
if [ "$sftp_check" -gt 0 ]
then
        echo '\n'
        echo "##################################"
        echo  ERROR: SFTP Transfer Not Completed
        echo  'SFTP to Blue Server failed'
        echo "##################################"
        echo `date`
        exit 1
fi

echo "Script Completed"
echo"Exiting the program on `date`"

# 6  
Old 08-25-2016
That are 100 lines only, so still no syntax error at line 157 possible. To me, that msg sounds like an unpaired single/double quote somewhere in the script.
# 7  
Old 08-25-2016
What about the second sftp_check?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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. (13 Replies)
Discussion started by: hemanthsaikumar
13 Replies

2. UNIX for Dummies Questions & Answers

SFTP error between UNIX to iSeries (Write Failed Broken Pipe)

Hi, I am iseries resource and having Issue in one of the sFTP failures between one of my job (Unix --> iSeries). The response to sending machine (Unix) is "Write Failed Broken Pipe". Appreciate any help Available on why this Issue happens, how can we replicate the same, what fixes can... (1 Reply)
Discussion started by: hamelchauhan
1 Replies

3. UNIX for Dummies Questions & Answers

Sftp from UNIX to mainframe

Hi, I have many scripts where i have used sftp for file transfer from unix box to unix box.. Now that we have to sftp files from unix to mainframe, i would like to know if that is possible. I just tried in the same way i did from unix to unix, but i got the error as connection refused. Are... (2 Replies)
Discussion started by: dnat
2 Replies

4. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

5. Shell Programming and Scripting

SFTP in UNIX

I need create a Shell script to do the SFTP process. How can i provide username and password in the script.I had the below code.But it ask for password.How can i add user name and password in this code echo "OK, starting now..." sftp -b /dev/fd/0 testwasds3l<<EOF cd /opt/isproj/VOM/Scripts... (2 Replies)
Discussion started by: morbid_angel
2 Replies

6. Shell Programming and Scripting

sftp to UNIX host

Hi, I am writing a shell script that securely connects to an UNIX host and transfer file(abc.txt) from the local machine to the host. sftp user@host get abc.txt bye The code doesn't work.. It throws error at line 2: get :Unknown get command. How can I rectify this problem? (2 Replies)
Discussion started by: Kishore_1
2 Replies

7. Shell Programming and Scripting

SFTP from Unix to Windows

Hi all Not sure where I should be posting this so apologies if it's in the wrong section. I'm trying to set up a system where we can copy a file (get) from a Windows server to a Unix server using SFTP in an automated way. I've installed CoreFTP Server on the Windows server and can connect... (2 Replies)
Discussion started by: huskie69
2 Replies

8. Linux

SFTP on SCO Unix

Hi, I have a request to install sftp on the Sco Unix Server. Request you please let me know the process for the installation of SFTP on Sco Unix Server. Thanks & Regards Arun (2 Replies)
Discussion started by: Arun.Kakarla
2 Replies

9. Shell Programming and Scripting

Error copying files from Unix (Solaris10) to Windows Server 2003 using scp/sftp

Hi, I have generated a Public/Private Key Pair in Solaris Unix (source) server and deployed the Public key in Windows 2003(target) server .ssh directory of user profile. When i try to connect(ssh, scp, sftp) from Unix, i'm getting below error message. Sun_SSH_1.1, SSH protocols 1.5/2.0,... (0 Replies)
Discussion started by: ajaykumarb
0 Replies

10. HP-UX

sftp from unix to NT

Hi, 1) I want help on SFTP,Some commands not working in SFTP,but working in FTP example: bin,ls -xt ,user. Any alternate methos for this 2) if I want download files from UNIX to NT,I am able to download,but file format not connverting according to UNIX format(in NT end of line \n,but in... (1 Reply)
Discussion started by: anthonykomma
1 Replies
Login or Register to Ask a Question