550 error when using Commons/Net

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();
 
V

varlagas

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
 
V

varlagas

Running the "handle" utility on the target machine I get 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 (by way of EfuClient.storeFile() ) has
been completed? It is this lock held that apparently prevents file
deletion and results in a 550 error.... Thx!
 
C

Chris Uppal

// ... and thus we need to back it up to another file
// and so that's what we do!
ftpClient.storeFile(fileName, efuFileUrl.openStream());

It doesn't seem to me that this stream is ever closed again. I'm not familar
with the FTP client API, but if it doesn't close the stream for you, then the
file will still be open when you try to delete it later. Which will then fail
(on Windows).

-- chris
 
G

Greg R. Broderick

(e-mail address removed) wrote in @m73g2000cwd.googlegroups.com:
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"

c.f. <http://www.faqs.org/rfcs/rfc765.html>

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
G

Greg R. Broderick

(e-mail address removed) wrote in @p79g2000cwp.googlegroups.com:
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?

What FTP server software are you using?

Can you successfully do a copy followed by a deletion manually (using an
FTP client from another host)?

Cheers
GRB


--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
V

varlagas

Thanks Chris!

After appropriately rewriting the pertinent piece of code (keeping the
input stream around in a variable and closing it after the file storing
is over with), it works fine!

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

URLConnection urlConnection = efuFileUrl.openConnection();
InputStream fileIn = urlConnection.getInputStream();

ftpClient.storeFile(fileName, fileIn);

fileIn.close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top