Remove remote files using SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove remote files using SFTP
# 1  
Old 04-10-2011
Remove remote files using SFTP

Hello All,
I am really looking for your help regards to the below issue.Smilie

My requirement is to get the files from the remote server using SFTP
and then remove the retrieved files in the remote directory. File names
are unique in the remote directory. so first I will need to get the files
,then know the file names and then remove the files with this file names.

I tried below code , Using this I can able to retrive the files and know the file names but unable to remove the files Smilie . Please check the code
and suggest me ....


Code:
sftp warnesftp@161.17.33.237 <<EOF
cd /home/warnersftp/Test/warn
get *.xml /home/lidca/intel/order
quit
EOF
ls /home/lidca/intel/order/*.xml >> filelist.txt
 
while read N
do
 echo >>todo.lst cd /home/warnersftp/Test/warn
 echo >>todo.lst rm $N
 echo >>todo.lst 
done <list.txt
echo >>todo.lst quit
sftp warnesftp@161.17.33.237 <todo.lst
rm todo.lst


Thanks
Vinay
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vinayparakala; 04-10-2011 at 08:20 PM.. Reason: code tags, please!
# 2  
Old 04-10-2011
Should use sftp -b batchfile user@host processing commands in batch (both for fetch and rm calls).

Filelist is in filelist.txt not list.txt

What error do you get with rm? Could it be you don't have permission to delete files on the sftp server? Can you rm files interactively using that login?
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 04-12-2011
Hi Chubler,

Thanks a lot for quick response ....I did change the code as you suggested but no use ...It's giving an error like file name couldn't find.

I can able to use rm files interactively and I have the permissions. I think the code is entirely wrong after WHILE READ N.

Can you please suggest me and save.....

---------- Post updated at 10:58 PM ---------- Previous update was at 02:12 AM ----------

Can any one please help me on this .....
# 4  
Old 04-12-2011
Can you post the transcript of the rm session, with the exact error message?
Do you have any "funny" characters in your file or directory names (eg star, space, quote, dollar signs, etc.)?

Are you cleaning out the file that is built with
Code:
lls /home/lidca/intel/order/*.xml >> filelist.txt

each time you run the script, otherwise files you deleted last session will still be in filelist.txt and will cause errors the 2nd and subsequent times they are passed to the rm phase.
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 04-14-2011
Hello Chubler ,

I have resolved this issue by myself ....But you only responded here and proposed some solution ...Thanks for your help again
# 6  
Old 07-31-2011
Hello Vinay

Can you update the solution you had for this. I too have the same requirement.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename (move) multiple files on remote server using sftp

I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help? #!/bin/ksh sftp -dev3 << ABC cd my_dir $(for i in TXT; do echo "ls *.$i" ; rename $x /new_dir/$x;... (1 Reply)
Discussion started by: Soham
1 Replies

2. Shell Programming and Scripting

Test if Remote server is up and running before SFTP'ing files (in batch mode)

Hello, In our Data Warehouse environment, before our batch SFTP jobs kick off to pull the files from remote servers, I would like to setup a pre-sftp job that would test if all the remote servers from where the files are being pulled, are up and running. If any one of the remote serer is... (2 Replies)
Discussion started by: Dippu
2 Replies

3. Shell Programming and Scripting

Help with moving files on remote server using sftp

I need to sftp a file ABC_sysdate.csv (File name with system date and timestamp) to a temporary directory on the remote server and once the file is copied I've to move the file from temporary directory to the main directory with the same name. I have to generate a new file every hour and repeat... (6 Replies)
Discussion started by: srinup
6 Replies

4. UNIX for Advanced & Expert Users

SFTP from remote server

Hi All,While sftp from remote server an error (/) is coming before the file in a script.Please find the below log. The file is on home directory on remote server. (6 Replies)
Discussion started by: kiranparsha
6 Replies

5. UNIX for Dummies Questions & Answers

SFTP to delete remote file

Hi guys In this scenario, i have been able to transfer the file from a remote server to my local server, but how to delete the file from remote server once its copied. I am using this command MYFILE=/tmp/MyFiLe.$$ echo rm FROM_DIR/K* >$MYFILE then sftp -b $MYFILE rm -f $MYFILE and I have... (1 Reply)
Discussion started by: rubel
1 Replies

6. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

7. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

8. Shell Programming and Scripting

Remove Duplicate Files On Remote Servers

Hello, I wrote a basic script that works however I am was wondering if it could be sped up. I am comparing files over ssh to remove the file from the source server directory if a match occurs. Please Advise me on my mistakes. #!/bin/bash for file in `ls /export/home/podcast2/"$1" ` ; do ... (5 Replies)
Discussion started by: jaysunn
5 Replies

9. Shell Programming and Scripting

SFTP setting with a remote server - need help

Hi All, i want to setup a STPF setting to a remote server. Could you please help on this. The setting i have done but its still asking for password. Could anyone throw some light on the same? Thanks in advance. Pankaj (1 Reply)
Discussion started by: panknil
1 Replies

10. Shell Programming and Scripting

commands to remote sftp

Hello, Is there a way to use wc, sed or other commands against remote sftp in a regular shell script? wc -c *.* | grep total | sed s/total// ? thanks in advance (0 Replies)
Discussion started by: chm0dvii
0 Replies
Login or Register to Ask a Question