bulk renaming of files in sftp using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bulk renaming of files in sftp using script
# 1  
Old 12-18-2011
bulk renaming of files in sftp using script

Hi,

Am using sftp (dsa method) to transfer 20 files from one server(sftp) to another (local). After the transfer is complete the files in the sftp server has to be renamed from .txt extension to .done extension ( aa.txt to aa.done, bb.txt to bb.done and likewise...).
I tried rename command but it works for only renaming of single file.
Can anyone help me in renaming all the 20 files in sftp using sample script.Smilie
# 2  
Old 12-18-2011
something like this may work ...
Code:
#!/usr/bin/ksh
for i in `ls *.txt`
do
sftp user@hostname << EOF
cd <PATH>
put $i `basename ${i} txt`done
EOF
done


Last edited by Scott; 12-18-2011 at 02:58 PM.. Reason: Please use code tags
# 3  
Old 12-18-2011
ok thank you so much Smilie wil try ... but wen we use put command and place the files, the sftp server will now have the older .txt files and the new .done files which are placed now using ur above script. I need to rename the files in the server not to place a copy of .done.
This process is done because after the admin see the .done renaming of files they place the next day files so that i can take the files by using ls *.txt
In the above process which u have said will take all the files (older and newer ones) also rite as files would not be renamed.
# 4  
Old 12-18-2011
Code:
#!/bin/sh
# wow this is easy
for file in `ls *.txt`
do
     scp $file foo@bar.com:/some/where/`basename txt ${file}`.done
done


Last edited by Scott; 12-18-2011 at 02:58 PM.. Reason: Please use code tags
# 5  
Old 12-18-2011
thanx ... wil try and let u know ... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming files in bulk.

Hi, I have a bunch of files which are named something like: Company Name~1234~X1234~X1-123.pdf I need to get them renamed something like: Company Name~1234(X1234)X1-123.pdf Once I have the X1234 inside () I have a piece of software which can use the X1234 bit. I will be receiving... (7 Replies)
Discussion started by: jcborland
7 Replies

3. Shell Programming and Scripting

Renaming bulk directories and subfiles

Hi, I have a directory with 100 subdirectories and each of these subdirectories has 1 file. Now I have to rename all these. The structure is "files directory has 100 SRR191639-SRR191718 subfolders and in each there is a file with the same name a subdirectory followed by .sra extension... (5 Replies)
Discussion started by: Diya123
5 Replies

4. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

5. Shell Programming and Scripting

Need script for renaming and moving files one by one...

Dears, I need your help! I got a problem and found some workaround solution but I donno how to realize it. I have a number of files (about 300 each day) and I need them to be renamed. All these files has fixed number of letters and name looks like this one:... (7 Replies)
Discussion started by: nypreH
7 Replies

6. Shell Programming and Scripting

Script for renaming files

I wanna back up the original version of files in a directory by appending .ORIG to them. I'm guessing I'd need CP and AWK in some form or fashion. Can someone give me a template? Thanks (3 Replies)
Discussion started by: stevenswj
3 Replies

7. Shell Programming and Scripting

script for renaming a batch of files

hi i have a folder full of files. some of the names are quite off because the dimensions were the same and i had to put a 'b' after the initial number so that it didnt overwrite. what i want is a script in unix to overwrite the filwe name leaving some of the title intact, e.g. below are some... (3 Replies)
Discussion started by: shabs1985
3 Replies

8. UNIX for Dummies Questions & Answers

Renaming Files using Shell Script

Hi Gurus, I have some files(all ending with .out as extension). Ex: aa1.out aa2.out aa3.out I would like to append each file with the current date to the end of the file so that they should become aa1_20090504.out. So I am using rename as follows: for i in path/aa* ; do mv $i... (5 Replies)
Discussion started by: asmfloyd
5 Replies

9. Shell Programming and Scripting

Need help renaming bulk file extentions

Hello, I am trying to rename bulk files however i dont think the rename/mv command is giong to help me here. here is a quick snapshot of the files I need to rename: 75008040 -rw-r----- 1 root root 8716 May 8 05:00 10.9.144.2 75008041 -rw-r----- 1 root root 11700 May 8 05:00 10.9.160.2... (10 Replies)
Discussion started by: jallan
10 Replies

10. Shell Programming and Scripting

Renaming files in a bash script

I'm doing a short batch script to compile po files producing output binary mo files. The compilation command is: msgfmt -o file.mo file.po so in order to compile I am appending .mo to the varible in a loop. It goes something like this: for i in `find . -name "*.po"` do echo... (2 Replies)
Discussion started by: Breen
2 Replies
Login or Register to Ask a Question