When listing files and it's subfiles within the directory in the FTP server here it seems to work when using the recursion call. Here I do it with recursion calling ListFolder(ftpClient, remoteFilePath) and it works, I have to try to do this without recursion. Is there any way to do this, any suggestions on how I can improve this code so I can do this without using recursion
private static void ListFolder(FTPClient ftpClient, String filesDirectory)
throws IOException
{
System.out.println("Listing folder " + filesDirectory);
FTPFile[] remoteFiles = ftpClient.listFiles(filesDirectory);
for (FTPFile remoteFile : remoteFiles)
{
if (!remoteFile.getName().equals(".") &&
!remoteFile.getName().equals(".."))
{
String remoteFilePath = filesDirectory + "/" + remoteFile.getName();
if (remoteFile.isDirectory())
{
ListFolder(ftpClient, remoteFilePath);
}
else
{
System.out.println("Found file " + remoteFilePath);
}
File downloadFile1 = new File(directory + "/" + remoteFile);
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadFile1));
ftpClient.retrieveFile(remoteFilePath, outputStream);
}
}