I need to move a file from the server's document folder into another folder FMS cannot write to. I tried using the BaseElements plugin, but it gives me "?" + error code 5 if I attempt to move the file or even just copy it. Anyone can get me out of this bad spot?
There are options, depending on the specifics of when, why, and how you need to move the files.
A lot of it centers around either giving the fmserver user more access or having a scheduled process run from another user move the file.
I'm guessing you don't have SSH access to the box. Or is it something that you want to do more than once?
Easiest is to link the target folder into the documents folder and grant write access to fmserver.
macOS/linux: ln -s pathToTarget pathToLinkName
windows: mklink /j pathToLinkName pathToTarget
A couple of other options:
- re-configure the FMS service to run as a user with sufficient rights; the choice of user is part of the installation process
- create a server-side system script schedule configured with an OS account that has enough rights and use the fmsadmin command line to trigger the schedule
- create a small folder-watcher service on Windows that will detect when a file is added to the FMS docs folder and will move it to where it needs to go <-- this would be my preference.
What I have today is a server-side script destined to run on a set schedule (regular intervals).
The script exports data to the documents folder and then edits some records in the database via a transaction. If the transaction fails, I want to delete the exported file, but if it succeeds, I want to move the file to a different directory.
It is a bit tricky. I'll look at the options outlined above and see what can be done.
@Bobino Is the server running on Windows ? If so 5 is probably Windows error 5 which means 'access denied'. Other posters come to the conclusion about access rights, which is in line with this.
Yes, it is a windows server and 5 does get reported as tied to access privileges on some websites I stumbled on. Thanks for all the help.
You can try Files.MoveFile function in MBS FileMaker Plugin in a server script.
If the file is open, you may not be able to move it on Windows. See Files.CanOpenFile function to check.
Agree with @WimDecorte.
Creating a watcher service is free, fast, and straightforward using a small Java program (works with any OS automatically).
Check out the link below:
Java WatchService API Tutorial - HowToDoInJava
I use this technique all over the place for all kinds of things. Mac, Linux (CentOS), or Windows, same code works perfectly (code abstracts path differences so you don't need to).
I'll be happy to help if you have questions.
Thank you all for your input. The customer's IT went with your recommendation and put something in place to move the file without me having to hit a single keystroke (those are the solutions I like the best).
If ever I in that bad place and have more control over the server, I'll come back here to implement your suggestions.