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
# 1  
Old 11-24-2014
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:
Code:
 sftp user@host <<EOF
           cd /path
           get *.txt
           rename *.txt *.txt.done
           EOF

How can I achieve this?
# 2  
Old 11-24-2014
This would have to be done in two steps:
Code:
( echo cd /path; echo get \*.txt ) | sftp -b - user@host
ls -1 | sed -ne '1icd /path' -e 's/^.*\.txt$/rename & &.done/p' | sftp -b - user@host

# 3  
Old 11-24-2014
I did not understand these commands. Please advise.
Also, is there any easier way to do this?
# 4  
Old 11-24-2014
Did you run each step of the pipeline? You also might want to check the manpages for sed and sftp
Code:
( echo cd /path; echo get \*.txt )

Generates
Code:
cd /path
get *.txt

, which is read by sftp. After the files have been retrieved, you need to create a series of renames.
Code:
ls -1 | sed -ne '1icd /path' -e 's/^.*\.txt$/rename & &.done/p'

does that, but this could have been done equally as well as:
Code:
(
  echo cd /path
  ls -1 *.txt | awk '{print "rename", $0, $0 ".done";' }
)

or
Code:
(
  echo cd /path
  for file in *.txt; do
    echo rename ${file} ${file}.done
  done
)

The two steps also prevents you from renaming a file that was not retrieved, had rename *.txt *.txt.done worked as you intended.

Last edited by derekludwig; 11-24-2014 at 07:36 AM.. Reason: typo
# 5  
Old 11-25-2014
Hi,

I understood the awk command but not the sed. Anyways, I tried using both the commands, but they are not renaming the files on remote server, even though the files are fetched.

Please give me another solution
# 6  
Old 11-25-2014
Please provide the script(s) you used and errors displayed.
# 7  
Old 11-25-2014
I suspect you do not have write permissions to the file (or containing folder) on that server.
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