Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

550 error when using Commons/Net

Thread view: 
varlagas@yahoo.com - 18 Jul 2006 10:24 GMT
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();
varlagas@yahoo.com - 18 Jul 2006 10:39 GMT
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
varlagas@yahoo.com - 18 Jul 2006 11:56 GMT
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!
Greg R. Broderick - 18 Jul 2006 14:04 GMT
varlagas@yahoo.com wrote in news:1153215546.168722.85350
@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
[quoted text clipped - 4 lines]
> 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

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb.usenet200606@blackholio.dyndns.org

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

Chris Uppal - 18 Jul 2006 12:14 GMT
>         // ... 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
varlagas@yahoo.com - 19 Jul 2006 08:31 GMT
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();
Greg R. Broderick - 18 Jul 2006 14:02 GMT
varlagas@yahoo.com wrote in news:1153214661.907074.93370
@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>

Signature

---------------------------------------------------------------------
Greg R. Broderick            gregb.usenet200606@blackholio.dyndns.org

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.