aspose file tools*
The moose likes I/O and Streams and the fly likes 550 error when using Commons/Net Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "550 error when using Commons/Net " Watch "550 error when using Commons/Net " New topic
Author

550 error when using Commons/Net

Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
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();
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
If I perform the copy alone or the deletion alone, then everything works fine. If I perform the deletion *following* the copy, it is only then that I get the 550 error problem. Seems like the copy operation creates some sort of dangling lock on the file that doesn't go away for the deletion to operate normally.

Has anyone ever experienced this or a similar problem? Does anyone have a clue?

Thx!

Panagiotis Varlagas
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
So, as I told you above, I am attempting to programmatically back up files lying in a folder in a Windows 2000 machine, by way of Java (Apache Commons/Net library). The Java code runs on a remote server (actually an AS/400 one) and accesses the Win2K machine, attempting to (i) copy the files to a backup folder on the Win2K machine and (ii) delete the original files. When the program merely copies or merely deletes the files, it works fine. However, if it first copies the files and subsequently attempts to delete them, deletion fails with a 550 FTP error:

"The process cannot access the file because it is being used by another process."

Running the "handle" utility on the target machine I got the following:

===============================================================================

Handle v3.2
Copyright (C) 1997-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

------------------------------------------------------------------------------
System pid: 8 NT AUTHORITY\SYSTEM
[...]
3C8: File (RW-) C:\Inetpub\ftproot\data_efu_in\INTER777

===============================================================================

(INTER777 is the file to be deleted.)

Does anyone have a clue as to why this handle is held on the file, long
after the copy file operation has
been completed? It is this lock held that apparently prevents file
deletion and results in a 550 error.... What should I do to overcome this problem? Thx!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 550 error when using Commons/Net