Operating System - HP-UX
1753905 Members
9951 Online
108810 Solutions
New Discussion юеВ

Re: ftp rename multiple files beginning with a leading .

 
Links Moodley
Advisor

ftp rename multiple files beginning with a leading .

I have a script in Unix to connect to a Windows based server that does mput of files called .639622018_001368083_4E1_20100506080500000_TP220.xml and .639622018_001368083_4E1_20100506080500000_TP217.xml , so I use mput .* in my script which works well. However I then need to rename both the files with one command and drop the leading . from the file names.
15 REPLIES 15
TTr
Honored Contributor

Re: ftp rename multiple files beginning with a leading .

How about renaming the files before the ftp starts? At that level you can do it with shell scripting. Another way might be to try the "nmap" ftp internal command. See the ftp man pages in your UNIX server.
Suraj K Sankari
Honored Contributor

Re: ftp rename multiple files beginning with a leading .

Hi,

Or you can rename with wild card character after coping the files

Suraj
Links Moodley
Advisor

Re: ftp rename multiple files beginning with a leading .

The reason for first creating the file with a leading . was that the routine on the remote server grabs the file almost instantly and if it is slow then data is left out. The rename must take place after the file has been successfully transferred.
Prasanth V Aravind
Trusted Contributor

Re: ftp rename multiple files beginning with a leading .


you can use this ... this will do the trick .. but you have to run it from that directory where you have these files


for i in ` find . -name ".*xml" -print `
do
new_name=` echo $i | sed 's_/._/_g' `
mv $i $new_name
done


gudluck
prasanth
Links Moodley
Advisor

Re: ftp rename multiple files beginning with a leading .

I have made several attempts to rename using wildcard but because of the leading . it does not rename all files. The rename works with full name of file and each rename is separate.I need to rename in one go.
Links Moodley
Advisor

Re: ftp rename multiple files beginning with a leading .

please note the the the target is Windows based server so the find command does not work there.
Prasanth V Aravind
Trusted Contributor

Re: ftp rename multiple files beginning with a leading .

This script which i given is workin on my linux box ....


[root@vm1 files]# ls -la
total 36
drwxr-xr-x 2 root root 4096 May 4 11:56 .
drwxrwxrwt 11 root root 4096 May 4 11:43 ..
-rw-r--r-- 1 root root 0 May 4 11:56 .239622018_001368083_4E1_20100506080500000_TP217.xml
-rw-r--r-- 1 root root 0 May 4 11:56 349622018_001368083_4E1_20100506080500000_TP217.xml
-rw-r--r-- 1 root root 0 May 4 11:43 .639622018_001368083_4E1_20100506080500000_TP217.xml
-rwxr-xr-x 1 root root 105 May 4 11:47 x.sh
[root@vm1 files]# ./x.sh
[root@vm1 files]# ls -la
total 36
drwxr-xr-x 2 root root 4096 May 4 11:56 .
drwxrwxrwt 11 root root 4096 May 4 11:43 ..
-rw-r--r-- 1 root root 0 May 4 11:56 239622018_001368083_4E1_20100506080500000_TP217.xml
-rw-r--r-- 1 root root 0 May 4 11:56 349622018_001368083_4E1_20100506080500000_TP217.xml
-rw-r--r-- 1 root root 0 May 4 11:43 639622018_001368083_4E1_20100506080500000_TP217.xml
-rwxr-xr-x 1 root root 105 May 4 11:47 x.sh
[root@vm1 files]# pwd
/tmp/files
[root@vm1 files]# cat x.sh
for i in ` find . -name ".*xml" -print `
do
new_name=` echo $i | sed 's_/._/_g' `
mv $i $new_name
done

[root@vm1 files]#


Gudluck
Prasanth
Prasanth V Aravind
Trusted Contributor

Re: ftp rename multiple files beginning with a leading .

Can you try this ..

copy these files to another directory
remove the leading "."
then mput to windows server
once mput completes, remove the copied files


Gudluck
Prasanth
Links Moodley
Advisor

Re: ftp rename multiple files beginning with a leading .

Below is the error message I get
ftp> !/usr/bin/1dotmove
for: Command not found.
do: Command not found.
i: Undefined variable.
i: Undefined variable.
new_name=: Command not found.
new_name: Undefined variable.
ftp> quit