System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

ftp rename multiple files beginning with a leading .

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

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

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.

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

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

Re: ftp rename multiple files beginning with a leading .

I cannot ftp the files without the leading . as the target system attempts to grab the file almost immediately therefore they suggested I create with leading . as the grab will ignore the leading .
Prasanth V Aravind
Trusted Contributor

Re: ftp rename multiple files beginning with a leading .

Totaly confused !!!!

okey ... pls provide the data for these..

what is files name in unix box ?? is it .639622018_001368083_4E1_20100506080500000_TP217.xml or with out dot (.) ??
do you want to add or remove dot ??
when you want to add/remove dot ??


Else can you saher the script with us?

Gudluck
Prasanth

Re: ftp rename multiple files beginning with a leading .

the file name on the unix before the ftp is with a leading . like .639622018_001368083_4E1_20100506080500000_TP220.xml.
The rename must take place on the Windows server after the ftp has been done.
Prasanth V Aravind
Trusted Contributor

Re: ftp rename multiple files beginning with a leading .

No Moodley ... you can't do it from your unix box... you can go for any bach script or perl script hosted on windows box..

I will suggest to try for perl script... But i am very new in perl .. so can't help you much..


still i try for my level best

:)

Gudluck
Prasanth

Re: ftp rename multiple files beginning with a leading .

Thank You Prasanth for your help thusfar.
Steven Schweda
Honored Contributor

Re: ftp rename multiple files beginning with a leading .

> [...] I then need to rename both the files
> with one command [...]

> I need to rename in one go.

Why "with one command"/"in one go"? I can't
think of any rename command (on any OS) which
will rename two files in this way at exactly
the same time.

Assuming that this (unspecified) Windows FTP
server supports a rename operation (Does
it?), then what would be the problem if you
renamed two files in two rename operations
instead of one?

> [...] the routine on the remote server
> grabs the file almost instantly [...]

That would seem to be your real problem.

In many cases, it's easier to leave the file
names unchanged, but put the files into a
different (unwatched) destination directory,
and then, after they've been transfered, move
(rename) them into the desired (watched)
destination directory. But, unless you
rename the whole directory, I see no way to
move/rename multiple files simultaneously.
(But I also don't understand the need to do
so.)