V
varlagas
I attempt to copy a file first and then to delete the original file,
using Commons/Net.
However, when attempting to perform the deletion I get a
"550 - The process cannot access the file because it is being used by
another process"
error!
Am I doing something wrong? Thx!
The code looks as follows:
COPY FILE
======================
URL efuFilesDirUrl = new URL(efuFilesDirUrlString);
BufferedReader in = new BufferedReader(new
InputStreamReader(
efuFilesDirUrl.openStream()));
// Logging on to the FTP server...
ftpClient.connect(serverName);
ftpClient.login(username, password);
// After connection attempt, check the reply code to verify
success
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
throw new EfuException("FTP server refused
connection.");
}
// actually back up the files
ftpClient.changeWorkingDirectory(folder + "/BACKUP");
{
String fileName;
while ((fileName = in.readLine()) != null) {
if (!fileName.equals("BACKUP")) {
// so, it's an actual file...
URL efuFileUrl = new URL(efuFilesDirUrlString
+ fileName);
// ... and thus we need to back it up to
another file
// and so that's what we do!
ftpClient.storeFile(fileName,
efuFileUrl.openStream());
}
}
}
in.close();
ftpClient.logout();
ftpClient.disconnect();
SUBSEQUENT DELETE FILE
======================
URL efuFilesDirUrl = new URL(efuFilesDirUrlString);
BufferedReader in = new BufferedReader(new
InputStreamReader(
efuFilesDirUrl.openStream()));
// Logging on to the FTP server...
ftpClient.connect(serverName);
ftpClient.login(username, password);
// After connection attempt, check the reply code to verify
success
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
throw new EfuException("FTP server refused
connection.");
}
ftpClient.changeWorkingDirectory(folder);
String fileName;
while ((fileName = in.readLine()) != null) {
if (!fileName.equals("BACKUP")) {
// so, it's an actual file...
// ... and thus we need to delete it
// and so that's what we do!
ftpClient.dele(fileName);
}
}
in.close();
ftpClient.logout();
ftpClient.disconnect();
using Commons/Net.
However, when attempting to perform the deletion I get a
"550 - The process cannot access the file because it is being used by
another process"
error!
Am I doing something wrong? Thx!
The code looks as follows:
COPY FILE
======================
URL efuFilesDirUrl = new URL(efuFilesDirUrlString);
BufferedReader in = new BufferedReader(new
InputStreamReader(
efuFilesDirUrl.openStream()));
// Logging on to the FTP server...
ftpClient.connect(serverName);
ftpClient.login(username, password);
// After connection attempt, check the reply code to verify
success
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
throw new EfuException("FTP server refused
connection.");
}
// actually back up the files
ftpClient.changeWorkingDirectory(folder + "/BACKUP");
{
String fileName;
while ((fileName = in.readLine()) != null) {
if (!fileName.equals("BACKUP")) {
// so, it's an actual file...
URL efuFileUrl = new URL(efuFilesDirUrlString
+ fileName);
// ... and thus we need to back it up to
another file
// and so that's what we do!
ftpClient.storeFile(fileName,
efuFileUrl.openStream());
}
}
}
in.close();
ftpClient.logout();
ftpClient.disconnect();
SUBSEQUENT DELETE FILE
======================
URL efuFilesDirUrl = new URL(efuFilesDirUrlString);
BufferedReader in = new BufferedReader(new
InputStreamReader(
efuFilesDirUrl.openStream()));
// Logging on to the FTP server...
ftpClient.connect(serverName);
ftpClient.login(username, password);
// After connection attempt, check the reply code to verify
success
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
throw new EfuException("FTP server refused
connection.");
}
ftpClient.changeWorkingDirectory(folder);
String fileName;
while ((fileName = in.readLine()) != null) {
if (!fileName.equals("BACKUP")) {
// so, it's an actual file...
// ... and thus we need to delete it
// and so that's what we do!
ftpClient.dele(fileName);
}
}
in.close();
ftpClient.logout();
ftpClient.disconnect();