SFTP file upload detection completed

I have an SFTP server (debian ssh server) where remote users upload one big file to a specific directory.

My problem is that I need to detect:

1) that a new file is present.

2) that the process / transfer is in progress.

What would be the best way to do this? Maybe there are some tools for this?

Thinking logically, I can detect in the first step that the new file is present in the directory. And in the second phase, then loop / wait until the SFTP user disconnects !? After that, I could start the next process ...

thanks and hurray, peter

+3


source to share


3 answers


For task 1) you can use the API inotify

to browse the directory for changes. You don't say which programming language you are using. In Perl you would use Linux::Inotify

, in Python pynotify

.



For task 2), one way is to wait until the ssh session is disconnected, the other is to also use inotify

to view file close notifications.

+2


source


I had a similar situation. Although I used caller ID, but the approach could help.

You can upload a file with some temporary extension. for example bigFile.txt.temp . After the file is downloaded, rename it to your desired filename ie bigFile.txt and delete the temporary file. JSCH ChannelSftp . In AOH, only one file is renamed. Therefore, you do not need to explicitly delete the temporary file.



Before downloading any new version of the file, check for a temporary file - bigFile.txt.temp. If it exists, it means that the file is currently being loaded. set the response code or wait for the session to disconnect.

0


source


In my use case, it is enough to check if any users are connected via SFTP. If so, I'll just review all locked files.

This can be done (on Linux / OpenSSH) using the command ps -ef

below.

Hooray!

0


source







All Articles