FTP Upload based on Filename
Greetings All,
My requirement is I have to read the filename, based on which the files are to be moved to different folders from where to different ftp sites. Eg. NNABRSTXYZ.txt where NN is a 2 digit number AB is a fixed code RST is folder(s) in working one (also ftp site) and XYZ is folder(s) inside RST (also folder in ftp site) Now the script has to read the filename and copy the file to respective XYZ folder(s) in respective RST folder(s) from which the files are to be put into XYZ folder of RST ftp site. This should happen only once for each file and be logged with time of action. Hope my query is understandable. I regret my English but need help. Someone please help me. Thank you all in advance. |
By script, if you mean shell script, then you probably want to look at parameter expansion to extract the pieces of the file name into variables which can in turn be used for the upload. Perl might be another option, too, if something more flexible and powerful than shell scripting is needed.
Also, I would highly recommend reconsidering the use of FTP. You can use SFTP with keys instead. With FTP, there is no way to secure it and your machine will eventually get broken into if you use it on a publicly facing machine. In contrast, SFTP works over SSH which has the most strongly vetted encryption available. |
Hi Turbocapitalist,
Thank you for the reply. Yes I meant to shell script in Linux. Eventually I will be considering SFTP when things are ready working. To further my question, there are around 50 RST folders and 10 XYZ folders in it. Also it would appreciable if the script triggers whenever any new files are created (not while being created). Thank you once again. |
Or you might move to SFTP now, while things are still working ;) It'll be cheaper to do it the right way the first time rather than messing with FTP and then redoing the script(s) for SFTP. Add to that the cost of needing to wipe the hardware and do a clean re-installation after an FTP-related break-in and SFTP is the clear choice.
However, regardless of that, once you have the script ready, you can use inotify to trigger using incron whenever a file is added to a specific directory. The first step is to have the script. What do you have so far? |
In addition using inotifywait which is part of the inotify-tools package you can monitor the directory for changes and run the script.
|
Thanks guys.
I still don't have any script ready yet. That is where I need you guys' help. |
Quote:
The style here is to help people over the bumps rather than write scripts out of whole cloth. |
Quote:
Can you please check and correct me? Next I need to copy only once. Then have to avoid copying when the file is being written or moved or copied into the watch folder. After that from the destination folders upload to FTP. Await your feedback. |
You do not need the ; at the end of your cp commands.
Use should use the absolute path in the cd command. The destination directories are all subdirectories of the files directory? Have you tested the script to see if it works? |
When using case you can use | for or
Code:
case answer in |
michaelk,
Hi. I will rectify and remove the ";" (semicolon) at the end of "cp" commands. Will rectify and use absolute path also. Yes the destination directories of "files" directory. I had tested and it is working. |
All times are GMT -5. The time now is 04:33 AM. |