我有一个允许用户上传文件的 ftp 客户端。我想确定哪个用户/主机/...上传了该文件。所有人都使用相同的用户名上传文件。唯一的区别是他们使用不同的计算机。
有什么方法可以跟踪哪个用户上传了该文件?
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();
}