Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.4k views
in Java FTP by (120 points)
I'm getting the files in a dir. For each file a transfer that file to my local disk and then deleting it on the ftp server.
My question is: What happens if somebody tries to write to a file, that I'm trying to delete? How can I prevent this? Is it possible to lock the dir while I do my job and unlock it again when I'm finished?

Here is my code:

FTPClient ftpClient = new FTPClient(address);
ftpClient.Login(userName,password);
ftpClient.Chdir(remoteDir);
string[] files = ftpClient.Dir();
foreach(string elm in files) {
ftpClient.Get(localDir+elm,elm);
ftpClient.Delete(elm);
}
ftpClient.Quit();

Ulrik

1 Answer

0 votes
by (161k points)
There is not that much you can do - it is up to the FTP server to handle multiple users.

One option would be to rename the file on the FTP server to a temporary unique name you generate, get the file, and then delete the file on the server.

I'm getting the files in a dir. For each file a transfer that file to my local disk and then deleting it on the ftp server.
My question is: What happens if somebody tries to write to a file, that I'm trying to delete? How can I prevent this? Is it possible to lock the dir while I do my job and unlock it again when I'm finished?

Categories

...