Reputation: 7228
I have a ftp client that allows users to upload files. I want determine which user/host/... uploaded that file.All people using the same username to upload file.the only difference is that they use different computer.
Is there any way I can track which user uploaded that file?
public static void uploadFileToServerViaSunFtp(final String source,final JPanel panel, final JTextArea textArea)
{
SwingWorker uploadWorker = new SwingWorker<Boolean,String>()
{
@Override
protected Boolean doInBackground() throws Exception
{
publish("File "+FilenameUtils.getName(source).concat(" starts uploading on ") + String.valueOf(Calendar.getInstance().getTime() + "\n"));
boolean success = false;
FtpClient client;
try
{
client = new FtpClient(server.getFtpServer());
client.login(server.getUsername(), server.getPassword());
client.cd("PC");
client.binary();
int BUFFER_SIZE = 10240;
byte[] buffer = new byte[BUFFER_SIZE];
File f = new File(source);
FileInputStream in = new FileInputStream(source);
// *** If uploading take long time, progress bar will show up ***
InputStream inputStream = new BufferedInputStream(
new ProgressMonitorInputStream(panel, "Uploading " + f.getName(), in));
OutputStream out = client.put(f.getName());
while (true) {
int bytes = inputStream.read(buffer);
if (bytes < 0)
break;
out.write(buffer, 0, bytes);
}
out.close();
in.close();
inputStream.close();
client.closeServer();
success = true;
}
catch (IOException e)
{
OeExceptionDialog.show(e);
}
return success;
}
@Override
protected void done()
{
super.done();
try {
if(get())
textArea.append("File "+FilenameUtils.getName(source).concat(" Uploaded successfully.\n"));
}
};
uploadWorker.execute();
}
Upvotes: 2
Views: 1164
Reputation: 32627
Files stored on an FTP server have owners (oid
) and groups (gid
).
The purpose of logging into an FTP server is to have you both authenticated and authorized. Therefore you should have different users as in 'different usernames' for each user who will be uploading the file.
It makes no sense to have the same username used by all your users, as this will make it impossible to make a distinction.
Checking the IP address is complete non-sense. The reason I am saying this is that anyone can hijack an IP address, if they're on your local network. There's little validation here and you can't trust your local DNS to do the job for you.
Simply use different usernames.
Upvotes: 5
Reputation: 46060
How is your client-side code related to the question? Of course the server knows the name of the user who logged in before uploading the file and from what IP address connection was made (except when IP address was masked by proxy/NAT). Moreover, properties of uploaded file are often set to have the owner and group on Unix or security attributes on Windows corresponding to owner and group of the user who uploaded the file.
Upvotes: 2