Need to check a condition using SFTP command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to check a condition using SFTP command
# 1  
Old 06-05-2013
Need to check a condition using SFTP command

HI,

I connected to a remote FTP server using sftp command.
Need to check if any files are present inside a folder in server directory and then remove if present.

The code should look like this
Code:
[sftp $USER@$HOST<<EOF 2>&1
cd $DIR
mget *$FILEEXT1
Here a condition like (if filecount>0 then )
rm *$FILEEXT1
quit
EOF]

How can this condition be written.

Thanks in advance,

Last edited by vbe; 06-05-2013 at 05:17 AM.. Reason: code tags next time for you code and data...
# 2  
Old 06-05-2013
There is no support for conditional expressions in sftp. A workaround for your situation might be to download the list of files, determine the files you wish to delete, if any, and if so do a second sftp to delete those files.
# 3  
Old 06-05-2013
In sftp commands i found '! command ' that can be used to run shell scripts. Can i use this command and execute if condition using sftp, if so how?

Thanks fpmurphy for the reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. UNIX for Dummies Questions & Answers

If condition to check one file newer than the other

Dear All, I'm new to unix scripting. I'm trying to write an utility script which has to check if one file is newer than another one. $3 $4 $5 $6 are files .txt. Help me please. for i in $3 $4 $5 $6 do if then echo "$1 is newer than $i" else echo "$i is newer than $1" fi (9 Replies)
Discussion started by: Manueldo
9 Replies

3. UNIX for Dummies Questions & Answers

Condition check using awk

Hi, I have a file in the following format "SYLVESTER,WILLARD G"|"S00633600"|"221052958A"|"H2256"|"015"|""|"00000042BASJ"|"665303"|"N"|"20100211"|"380.4"|""|""|""|"5400"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P" "PURINGTON-KELLEY,C"|"S00808783"|"029424717A"|"H2256"|"024"|"MEMBER JOINED... (3 Replies)
Discussion started by: nua7
3 Replies

4. Shell Programming and Scripting

sed to check two condition need solution

Hi, I am having a file in below format server-1 Win2008:server-1-1700,1774,290104720,290104987:server-1 server-2 AIX:server-2-:server-2 server-2 I want the output like this Win2008:server-1-1700,1774,290104720,290104987:standalon-server AIX:server-2-:VIO-Sever I used the... (7 Replies)
Discussion started by: ranjancom2000
7 Replies

5. UNIX for Dummies Questions & Answers

SFTP IF Condition

Hi , I need to write a IF condition to know if a SFTP file transfer is successful or not and send email if its failed. `sftp username@servername <<comm1 cd /directory put filename comm1 bye` I use above commands for my connections. So please help me to write a IF statement. I tried... (1 Reply)
Discussion started by: krishna87
1 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. 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

8. Shell Programming and Scripting

How to take a full sentence and check the condition?

I have one input file and content of file is : --------------------------------------------------- Input.txt --------------------------------------------------- american express Bahnbau GmbH Bahnbau GmbH CRH Europe crh europe Helgeland Ferdigbetong AS... (8 Replies)
Discussion started by: humaemo
8 Replies

9. Shell Programming and Scripting

WHILE LOOP CONDITION CHECK

Hello I want to compare values of two variables as CHECK condition in a while loop. eg: var1=0 var2=10 while do echo " $var1 " var1=`expr $var1 + 1` done However this is giving error.How to do it in a proper manner? Thanks. (3 Replies)
Discussion started by: dashing201
3 Replies
Login or Register to Ask a Question