Browse Source

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>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269268 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
1c03d47380
2 changed files with 56 additions and 40 deletions
  1. +4
    -0
      WHATSNEW
  2. +52
    -40
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

+ 4
- 0
WHATSNEW View File

@@ -142,6 +142,10 @@ Fixed bugs:
* <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
===========================================



+ 52
- 40
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -71,6 +71,14 @@ import org.apache.tools.ant.types.*;
* <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 @@ public class FTP

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 @@ public class FTP
}
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
}
}
}
}
}

Loading…
Cancel
Save