Renaming multiple files in sftp server in a get files script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming multiple files in sftp server in a get files script
# 8  
Old 12-27-2014
Hi,

I also had a similar requirement and found that we cannot rename multiple files in the remote server using wild character and below are the steps which i followed to achieve this.

1. First you need to receive the files.
2. Generate rename command for the files which you have received.
3. Again connect to the remote server passing the rename command as input.

Sample code which I used:

Code:
#!/usr/bin/ksh  
###The below shell script is used to receive and rename files in remote server, and below is the steps followed.  
###First you need to receive the xml files.  
###Generate rename command for the files which you have received.  
###Again connect to the remote server passing the rename command as input.  
  
# Shell script to receive xml files from remote machine #  
cd /home/oracle/XML_FILES/   ## local directory  
  
#Clear renamescript.txt file at each execution#  
cat /dev/null > /home/oracle/FTP_SCRIPTS/renamescript.txt  
sftp userid@remote_server <<END  
cd /home/user/XML  ## remote directory  
prompt  
mget *  
bye  
END  
  
# For generating rename script #  
ls /home/oracle/XML_FILES/ > /home/oracle/FTP_SCRIPTS/count  
for i in `cat /home/oracle/FTP_SCRIPTS/count`  
do  
{  
print `echo rename /home/user/XML/$i /home/user/XML_BACKUP/$i` >> /home/oracle/FTP_SCRIPTS/renamescript.txt  
};  
done  
  
# To rename files in remote machine #  
sftp userid@remote_server < /home/oracle/FTP_SCRIPTS/renamescript.txt  
bye  
#End of script

Thanks,

Last edited by rbatte1; 01-22-2018 at 09:39 AM..
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

Sftp script to get multiple files at the same time

i have to log into an sftp server to get multiple files. im typing this post from a remote location and i dont have the script i wrote with me. but i got the sftp script to work by logging into the sftp server file by file. meaning, sftp to the server, "mget -p" or "get -p" one file at a time.... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. HP-UX

Shell script to sftp files to file server.

Hi, I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run. The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script. I tried with below snippet:-... (2 Replies)
Discussion started by: happysingh
2 Replies

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

5. Shell Programming and Scripting

Renaming Multiple Files in FTP Server

Hi Friends, I have a requirement to get multiple files from ftp(remote) server and once the files is copied to local machine , I need to move the files on to a different directory in ftp machine. FTP Machine : 9.9.999.999 Source File Directory : /ftpuser File Pattern: TMS* Now I have... (1 Reply)
Discussion started by: lokeshbao87
1 Replies

6. Shell Programming and Scripting

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

7. Shell Programming and Scripting

Renaming multiple files with a shell script

Hey guys, I'm really new to UNIX and shell scripting in general. For my internship I need to rename a bunch of files. Specifically, I need to change the first letter of each of the files to lowercase and I have to change the endings so they all basically look like "file_cone.jpg". I know I... (4 Replies)
Discussion started by: jjzieve
4 Replies

8. Solaris

how to get multiple files using sftp from a windows server

I need to get multiple files from a windows server to a solaris server using sftp, I tried it but only can get one file at a time ( I'm unable to use a wild card character using sftp) hoe do i do this. any light on this is appreciated. Ram. (3 Replies)
Discussion started by: ramky79
3 Replies

9. Shell Programming and Scripting

Utility or script for renaming files on UNIX web server

Greetings! Does anyone know of a utility or a script for renaming files on a UNIX web server? I've seen several of these types of renaming utilities for Windows, but none for UNIX. I have 10,000 files that I need to rename in a several tier (deep) web site directory. I have the original... (2 Replies)
Discussion started by: everettr
2 Replies

10. UNIX for Advanced & Expert Users

Utility or script for renaming files on UNIX web server

Greetings! Does anyone know of a utility or a script for renaming files on a UNIX web server? I've seen several of these types of renaming utilities for Windows, but none for UNIX. I have 10,000 files that I need to rename in a several tier (deep) web site directory. I have the original... (1 Reply)
Discussion started by: everettr
1 Replies
Login or Register to Ask a Question