fix for ftp client: suppress bad directory listing time-out

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7348 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent d4a1a1850b
commit 3d945bb442

@ -1347,12 +1347,12 @@ public class FTPClient {
// read file system data // read file system data
String line; String line;
final ArrayList<String> files = new ArrayList<String>(); final ArrayList<String> files = new ArrayList<String>();
try {
while ((line = ClientStream.readLine()) != null) { while ((line = ClientStream.readLine()) != null) {
if (!line.startsWith("total ")) { if (!line.startsWith("total ")) {
files.add(line); files.add(line);
} }
} }
// after stream is empty we should get control completion echo // after stream is empty we should get control completion echo
/*reply =*/ receive(); /*reply =*/ receive();
@ -1361,9 +1361,8 @@ public class FTPClient {
// shutdown connection // shutdown connection
ClientStream.close(); // Closing the returned InputStream will ClientStream.close(); // Closing the returned InputStream will
closeDataSocket(); // close the associated socket. closeDataSocket(); // close the associated socket.
} catch (IOException e) {
// if (!success) throw new IOException(reply); }
files.trimToSize(); files.trimToSize();
return files; return files;
} }
@ -2518,33 +2517,25 @@ public class FTPClient {
} }
} }
public StringBuilder dirhtml(String remotePath) { public StringBuilder dirhtml(String remotePath) throws IOException {
// returns a directory listing using an existing connection // returns a directory listing using an existing connection
try {
if (isFolder(remotePath) && '/' != remotePath.charAt(remotePath.length()-1)) { if (isFolder(remotePath) && '/' != remotePath.charAt(remotePath.length()-1)) {
remotePath += '/'; remotePath += '/';
} }
String pwd = pwd();
final List<String> list = list(remotePath, true); final List<String> list = list(remotePath, true);
if (remotesystem == null) { if (remotesystem == null) try {sys();} catch (IOException e) {}
sys();
}
final String base = "ftp://" + ((account.equals("anonymous")) ? "" : (account + ":" + password + "@")) final String base = "ftp://" + ((account.equals("anonymous")) ? "" : (account + ":" + password + "@"))
+ host + ((port == 21) ? "" : (":" + port)) + ((remotePath.length() > 0 && remotePath.charAt(0) == '/') ? "" : pwd() + "/") + host + ((port == 21) ? "" : (":" + port)) + ((remotePath.length() > 0 && remotePath.charAt(0) == '/') ? "" : pwd + "/")
+ remotePath; + remotePath;
return dirhtml(base, remotemessage, remotegreeting, remotesystem, list, true); return dirhtml(base, remotemessage, remotegreeting, remotesystem, list, true);
} catch (final java.security.AccessControlException e) {
return null;
} catch (final IOException e) {
return null;
}
} }
public static StringBuilder dirhtml( public static StringBuilder dirhtml(
final String host, final int port, final String remotePath, final String host, final int port, final String remotePath,
final String account, final String password) { final String account, final String password) throws IOException {
// opens a new connection and returns a directory listing as html // opens a new connection and returns a directory listing as html
try {
final FTPClient c = new FTPClient(); final FTPClient c = new FTPClient();
c.open(host, port); c.open(host, port);
c.login(account, password); c.login(account, password);
@ -2552,11 +2543,6 @@ public class FTPClient {
final StringBuilder page = c.dirhtml(remotePath); final StringBuilder page = c.dirhtml(remotePath);
c.quit(); c.quit();
return page; return page;
} catch (final java.security.AccessControlException e) {
return null;
} catch (final IOException e) {
return null;
}
} }
public static StringBuilder dirhtml( public static StringBuilder dirhtml(
@ -2619,12 +2605,11 @@ public class FTPClient {
dir(host, remotePath, "anonymous", "anomic"); dir(host, remotePath, "anonymous", "anomic");
} }
public static void dirAnonymousHtml(final String host, final int port, final String remotePath, public static void dirAnonymousHtml(final String host, final int port, final String remotePath, final String htmloutfile) {
final String htmloutfile) { try {
final StringBuilder page = dirhtml(host, port, remotePath, "anonymous", "anomic"); final StringBuilder page = dirhtml(host, port, remotePath, "anonymous", "anomic");
final File file = new File(htmloutfile); final File file = new File(htmloutfile);
FileOutputStream fos; FileOutputStream fos;
try {
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
fos.write(page.toString().getBytes()); fos.write(page.toString().getBytes());
fos.close(); fos.close();

Loading…
Cancel
Save