How to automate file transfer from one directory to another directory server based on File name.?

A

Anil Maharjan

Guest
Hello all,
I want to transfer a file from one server directory location to another server into multiple directory location based on file name?
Lets say I have a list of file in with multiple file name having same ext.
\home\server1\File\20140827\
File1_A_20140827_01.unl
File1_A_20140827_02.unl
...
File2_B_20140827.unl
File2_C_20140827.unl
ans so on.

Now I need to transfer these files into another ftp location into multiple directory
\home\server2\File\
for files related to A
into \home\server2\File\A\20140827
mput *A*
for files related to B into
\home\server2\File\B\20140827
mput *B*

and so on for following days
into \home\server2\File\A\20140828
...
I can do this by manually but it's taking time to do this for day by day basis.
so, can anyone help me one this to write the shell script or some automation script to overcome with this .
Your help is much appreciated.

Thanks
Anil Maharjan
 


I would write a Perl script using the FTP interface. The script could break down the names into elements, make decisions based on that, then put the files into the proper directory on the remote.

Actually, you shouldn't use FTP - it's a security risk. SFTP or SSH are better, but I won't belabor that point.

The code is not complex - it's just a bit of manipulating.
 
Thanks for your response and suggestion , well actually speaking I have no idea regarding perl script but I can learn if i need.
Yes , FTP is risky but I am using internal network only so I think there won't be much issue on this.
Also, it would be great if you can share some links or post or some helpful code then it would be helpful.
Thanks again.
Anil
 
...or any language would work...

You are taking a file name, and splitting the name into an array by the underscore.

In Perl, if $filename = "File1_A_20140827_01.unl", you would

@filenamepieces = split "_", $filename;

Then,
$filenamepieces[0] = "File1"
$filenamepieces[1] = "A"
$filenamepieces[2] = "20140827"
$filenamepieces[3] = "01.unl"

These array pieces can then map to the folder you need to send it to / create and send it to. At this point, you have the "info you need" to drive a script.

You can do this an any language - or a shell script - it's just a bit easier in Perl (for me at least). Perl has a decent FTP interface, so you could use that to cd to wherever you need and feed it the files to place in the appropriate directory on the remote server.
 
Seems I can not add attachments link

Sorry


Search Google : website is "linuxlinks period com" page : "FileTransfer dot html"
 
Last edited:
You should write a bash script and put it on the server you want to copy the files. It's good idea create a cron with you script to schecule the task . Another option is use public keys and use "scp" command to copy the files.
 

Members online


Latest posts

Top