2

I have no idea if this is possible or not, and if so where to actually start doing so.

Effectively we have an SFTP server, and I'd like to be able to Archive off the files after they have been downloaded. The Server has multiple rooted users, so I'd need to create a process that can repeat itself across each User's root folder.

Each user does, however, have their folder in the same initial directory (not home), and each has the same file structure afterwards (with an In, Out, and Archive folder).

Is a there a way to achieve this? I did wonder about have a cron task running at say the end of each day, but if so, I would like to handle to unlikely event of the file being overwritten post download. For example, if someone obtained a file from us, and then contacted us to advise that something needed to be amended. The file would then need to be saved in the Out Folder again, but there would be little way I could guarantee that the staff member did not overwrite the previously downloaded file, rather than Suffixing it with something like "v2".

I'm not sure how to achieve to know that the file was downloaded. Are you able to have an event run when a file is accessed on Ubuntu, or by a specific user?

If not, i could check the logs, which would help, which I would show a list of what files have been accessed, however, the logs don't give the year. Considering that this is going to be an on going solution, in 12 months time I don't want the system thinking "this file has been accessed", when what actually happened is a file of the same was access over a year ago.

Anything would need to run server side. Clients will all be external to the company, so I have little to know control over what software, etc, that would use to connect to our server.

It matters if the file is overwritten, as if it's been changed the last thing i want is for the file to be archived. Then the client can't download the updated file. If a new file, with a different name is there, it is clearly a new file.

If you need any specifics (log formats, etc), please let me know.

File Structure (each user has their own folder, so ):

/sftpshare

->/userone

->->/In

->->/Out

->->/Archive

->/usertwo

->->/In

->->/Out

->->/Archive

Files that I want to check have been downloaded are in the Out Folder. Files in the In folder don't need to be checked, as this are items we have received, and are archived by a process we already have running when the file is read by our SQL server.

I'm not really looking for someone to give me a full script (Unless you are feeling overly helpful!), but if anyone someone can point me in the right direction and where I might need to start and some snippets of script I might need, that would be extremely useful.

Thanks anyone that can help.

Thom

  • Please edit your question and give us some more detail. How can you know if a file has been downloaded? Is this script going to run on the client or the server? What difference does it make if a file was overwritten or renamed? – terdon Sep 22 '16 at 12:46
  • Added my comments at the end of my post – Larnu Sep 23 '16 at 10:02
  • Yes, you should be able to run a command on file access using inotify. Alternatively, you should also be able to compare access times (see stat file). Can you confirm that downloading the file changes the access time listed? – terdon Sep 23 '16 at 10:36
  • Yes, downloading the file via SFTP does indeed change the Access time. it doesn't change the modify or change times though. With regards to inotify, I did have a look at this, however, it seems that every folder has to be specified. If an additional account is added 9and therefore new folder), is this fairly easy to add in automatically. if a file is overwrite, does inotify see that differently to it being read, and can it see who read the file (as I want to make sure the user who accessed it is the user who's folder it is, not someone in house looking at it)? Thanks – Larnu Sep 23 '16 at 12:07
  • You'll have to test it (which is why I haven't posted an answer). Adding a new dir should be simple (although you can probably also just specify the parent directory). However, the details will depend on how exactly you've set up your system. If you show an example directory structure, we can give you more details. – terdon Sep 23 '16 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.