I want to move all new added file from a directory (ftp directory) to another directory (Documents). I use vsftpd
on my ubuntu 22.04.
I've created a simple code to move new file like this
import shutil
import os
source_dir = 'source_dir' # ftp directory
target_dir = 'target_dir'
while True:
file_names = os.listdir(source_dir)
for file_name in file_names:
# this line is executed before the file is completely added.
shutil.move(os.path.join(source_dir, file_name), target_dir)
print(file_name+" was moved")
but the moved file is corrupted, the size is smaller than original file. I think it caused when I've added a new file, it was moved before the file completely added/copied.
Then I tried to use watchdog
library, but it was not worked on ftp directory (worked on non-ftp directory).
The file is from camera controller device to my ftp folder on ubuntu, not from my own code using php
, python
, C#
, or another language. So I can't change the source side (camera controller).