ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
Date Wed, 04 Jul 2001 15:05:21 GMT
bodewig     01/07/04 08:05:20

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
  Log:
  properly recurse remote directory in <ftp>
  
  PR: 2285
  Submitted by:	Jean-Francois.Morneau@ift.ulaval.ca (Jean-Francois Morneau),
                  Roger Vaughn <rogervaughn@yahoo.com>
  
  make sure <ftp> disconnects from the server when it's done
  
  Submitted by:	Brian Rumple <brumple@VALUBOND.COM>,
                  Roger Vaughn <rogervaughn@yahoo.com>
  
  Revision  Changes    Path
  1.119     +4 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- WHATSNEW	2001/07/04 14:40:25	1.118
  +++ WHATSNEW	2001/07/04 15:05:17	1.119
  @@ -142,6 +142,10 @@
   * <copy> will remove target file (if it exists) before writing to it -
     this avoids problems with links on filesystems that support them.
   
  +* <ftp> now properly recurses remote directories.
  +
  +* <ftp> closes remote connection when it's done.
  +
   Changes from Ant 1.2 to Ant 1.3
   ===========================================
   
  
  
  
  1.6       +52 -40    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FTP.java	2001/01/11 11:53:52	1.5
  +++ FTP.java	2001/07/04 15:05:19	1.6
  @@ -71,6 +71,14 @@
    *   <li><strong>list</strong> - create a file listing.</li>
    * </ul>
    *
  + * <strong>Note:</strong>
  + * Some FTP servers - notably the Solaris server - seem to hold data ports
  + * open after a "retr" operation, allowing them to timeout instead of
  + * shutting them down cleanly.  This happens in active or passive mode,
  + * and the ports will remain open even after ending the FTP session.
  + * FTP "send" operations seem to close ports immediately.  This behavior
  + * may cause problems on some systems when downloading large sets of files.
  + *
    * @author Roger Vaughn <a href="mailto:rvaughn@seaconinc.com">rvaughn@seaconinc.com</a>
    * @author Glenn McAllister <a href="mailto:glennm@ca.ibm.com">glennm@ca.ibm.com</a>
    */
  @@ -154,50 +162,55 @@
   
                   FTPFile[] newfiles = ftp.listFiles();
                   if (newfiles == null) {
  -                    return;    // no files in directory.
  +                    ftp.changeToParentDirectory();
  +                    return;
                   }
   
                   for (int i = 0; i < newfiles.length; i++) {
                       FTPFile file = newfiles[i];
  -                    String name = vpath + file.getName();
  -                    if (file.isDirectory()) {
  -                        if (isIncluded(name)) {
  -                            if (!isExcluded(name)) {
  -                                dirsIncluded.addElement(name);
  -                                if (fast) {
  -                                    scandir(name, name + File.separator, fast);
  +                    if (!file.getName().equals(".") && !file.getName().equals(".."))
{
  +                        if (file.isDirectory()) {
  +                            String name = file.getName();
  +                            if (isIncluded(name)) {
  +                                if (!isExcluded(name)) {
  +                                    dirsIncluded.addElement(name);
  +                                    if (fast) {
  +                                        scandir(name, vpath + name + File.separator, fast);
  +                                    }
  +                                } else {
  +                                    dirsExcluded.addElement(name);
                                   }
                               } else {
  -                                dirsExcluded.addElement(name);
  +                                dirsNotIncluded.addElement(name);
  +                                if (fast && couldHoldIncluded(name)) {
  +                                    scandir(name, vpath + name + File.separator, fast);
  +                                }
                               }
  -                        } else {
  -                            dirsNotIncluded.addElement(name);
  -                            if (fast && couldHoldIncluded(name)) {
  -                                scandir(name, name + File.separator, fast);
  +                            if (!fast) {
  +                                scandir(name, vpath + name + File.separator, fast);
                               }
  -                        }
  -                        if (!fast) {
  -                            scandir(name, name + File.separator, fast);
  -                        }
  -                    } else {
  -                        if (file.isFile()) {
  -                            if (isIncluded(name)) {
  -                                if (!isExcluded(name)) {
  -                                    filesIncluded.addElement(name);
  +                        } else {
  +                            if (file.isFile()) {
  +                                String name = vpath + file.getName();
  +                                if (isIncluded(name)) {
  +                                    if (!isExcluded(name)) {
  +                                        filesIncluded.addElement(name);
  +                                    } else {
  +                                        filesExcluded.addElement(name);
  +                                    }
                                   } else {
  -                                    filesExcluded.addElement(name);
  +                                    filesNotIncluded.addElement(name);
                                   }
  -                            } else {
  -                                filesNotIncluded.addElement(name);
                               }
                           }
                       }
                   }
  +                ftp.changeToParentDirectory();
               } catch (IOException e) {
                   throw new BuildException("Error while communicating with FTP server: ",
e);
               }
           }
  -    }        
  +    }
   
       /**
        * Sets the remote directory where files will be placed.  This may
  @@ -795,20 +808,19 @@
           }
           finally
           {
  -            /*
  -              if (ftp != null && ftp.isConnected())
  -              {
  -              try
  -              {
  -              // this hangs - I don't know why.
  -              ftp.disconnect();
  -              }
  -              catch(IOException ex)
  -              {
  -              // ignore it
  -              }
  -              }
  -            */
  +            if (ftp != null && ftp.isConnected())
  +            {
  +                try
  +                {
  +                    log("disconnecting", Project.MSG_VERBOSE);
  +                    ftp.logout();
  +                    ftp.disconnect();
  +                }
  +                catch(IOException ex)
  +                {
  +                    // ignore it
  +                }
  +            }
           }
       }
   }
  
  
  

Mime
View raw message