Quillion
Quillion

Reputation: 6476

Copy file with a lock on it

I have an application running on a server which is doing stuff and writing everything it does to a log file.
I also have secondary application which is kind of like a monitoring panel also running on the server but is a different process. What I would like to do is the following:

I would like my monitoring file to be able to copy the log file which currently has a lock on it from the other application and then email it to me. I have tried using scp to connect to the server and copy it manually to my computer(and it did work), however I would like to be able to do that through my java monitoring application. And I have no idea where to start.

Upvotes: 1

Views: 116

Answers (1)

copeg
copeg

Reputation: 8348

I have tried using scp to connect to the server and copy it manually to my computer(and it did work)

The JSch library has a ScpFrom module that you can use to scp copy the data from the server to your computer or application. This can be done by one of the following:

  1. Manually running the module (eg java -jar)
  2. Copying the source of the module into your project and adding the JSch library to classpath (more programmatic control - preferred approach)
  3. Using the library module programmatically eg String[] args = {user@remotehost:file1" "localfile"}; SCPFrom.main(args);

Upvotes: 1

Related Questions