Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners JAVA Code for Getting List of Directories and its SubDirectories from FTP server
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Mayank Soni
JAVA Code for Getting List of Directories and its SubDirectories from FTP server
2 Answer(s)      2 years and 8 months ago
Posted in : Java Beginners


**Hi. I am trying to get list of all directories and sub directories and its files from "FTP" and want to show in Jtree but i am unable to do it.Please Give me some code and also explain it. Thanks**

> Mayank Soni


Advertisement
View Answers

August 29, 2012 at 6:09 PM


public class FTPManager
{

    private static FTPManager ftpManager;


    private FTPManager(){}

    public static FTPManager getInstance()
    {
          if(ftpManager!=null)
          {
              return ftpManager; 
          }
           else
           {      ftpManager= new FTPManager ();
                   return ftpManager;
            }
    }


    public static void main(String[] args) throws Exception
    {
        FTPConnector ftpConnector = new FTPConnector("ftp server url", "username", "password");
        FTPClient ftpClient = ftpConnector.getFTPConnection();
        FTPManager ftpManager= FTPManager.getInstance();
        directoryManager.scanDirectoryTree(ftpClient);
    }

    private  void scanDirectoryTree(FTPClient ftpClient) throws IOException
    {
        FTPFile[] ftpFiles = ftpClient.listFiles();
        System.out.println("Files inside FTP Base");
        for (FTPFile ftpFile : ftpFiles)
        {
            if (ftpFile.isFile())
            {
                System.out.println("File Name :" +ftpFile.getName());               
            }
        }
        System.out.println("Directories and Subdirectories inside FTP Base");
        for (FTPFile ftpFile : ftpFiles)
        {
             if (ftpFile.isDirectory())
            {
                String dirName=ftpFile.getName();
                System.out.println("Directory Name :"+dirName);
                scanDirectoryTree(ftpClient, dirName);
            }
        }
    }

    private static void scanDirectoryTree(FTPClient ftpClient,String directory) throws IOException
    {   

       FTPFile[] ftpFiles =ftpClient.listFiles(directory);

        if (ftpFiles.length == 0) {
            System.out.println("no files in " + directory);
        }
        else
        {
            System.out.println("Files and sub directories inside the directory :"+directory);
        }
        for (FTPFile ftpFile : ftpFiles)
        {
            if (ftpFile.isFile())
            {
                System.out.println("File Name :"+directory+"\\" + ftpFile.getName());   
            }
        }
        for (FTPFile ftpFile : ftpFiles)
        {
            if (ftpFile.isDirectory())
            {
                String dirName=directory+"\\"+ftpFile.getName();
                scanDirectoryTree(ftpClient, dirName);
            }
        }

    }

}


August 29, 2012 at 6:19 PM


Hi Soni,

This will list out the files,directories and sub directories inside ftp.You can utilize this code for your reference.



Related Tutorials/Questions & Answers:
JAVA Code for Getting List of Directories and its SubDirectories from FTP server
JAVA Code for Getting List of Directories and its SubDirectories from FTP server  **Hi. I am trying to get list of all directories and sub directories and its files from "FTP" and want to show in Jtree but i am unable to do
List all directories on FTP Server
In this section you will learn how to list all the directories on FTP server using java
Advertisements
FTP Server : List Files and Directories
In this tutorial we will discuss how to list files and directories on FTP server using java
Java list directories
Java list directories In this section, you will learn how to display the list of directories from a particular directory. Description of code: As you all... used the methods of File class to retrieve the list of directories from
Java FTP
be downloaded from the apache website. View examples of Java FTP at: FTP Server...; Hello, See this also List all directories on FTP Server Thanks... share me the sample Java FTP code? Thanks   Hi, There are many FTP
Java Connect to and FTP Server
Java Connect to and FTP Server  What is the code for Java Connect to and FTP Server? How to establish a connection to FTP server in Java? Thansk... the apache commons library to connect/login to FTP server. Link of complete example
FTP Server: List all files name
This tutorial represents how to list the entire files name on FTP server using java
FTP Programming in Java tutorials with example code
: Change working directory FTP Server : List Files and Directories... size on FTP Server List all directories on FTP Server FTP... will learn how to create program in Java that connects to FTP server and upload
Implementing FTP in Java Code
Implementing FTP in Java Code  Hi, My job is to write a program in Java in my project. I have to implement FTP in my Java Code. Share me some of the code of Implementing FTP in Java Code. Thanks   Hi, Apache ftp
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
how to creat ftp server on java
how to creat ftp server on java  ftp server investigation requirment ER diagram flow chart source code
ftp server
ftp server  ftp server
ftp server
ftp server  ftp server
ftp server
ftp server  ftp server
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from... to the action. My action is getting called however, i am not sure how to pass
FTP server
FTP server  How to store a series of files in a ftp server using java
connect ftp from java program
connect ftp from java program  Hi, I need to connect to the ftp and get the files through a java program.. I wrote the following code... import... client = new FTPClient(); client.connect("ftp://111.111.111.111
connect ftp from java program
connect ftp from java program  Hi, I need to connect to the ftp and get the files through a java program.. I wrote the following code... import... client = new FTPClient(); client.connect("ftp://111.111.111.111
FTP Server
FTP Server  i'm working on ftp server if one client has uploaded a file i need to save the details of the user who has uploaded the file like username,filename & ipaddress using java
Java FTP Library
Java FTP Library        The Java Ftp Library Let's imagine a situation where we want to write a pure Java application that must download files from
how to copy the directory in to ftp server using java
how to copy the directory in to ftp server using java  how to copy the directory in to ftp server using java ?   Hello venaktehs As much...("MKD"+directoryName); Change the working directory : // Here "ftp" is the Object
upload and download files from ftp server using servlet - Ajax
upload and download files from ftp server using servlet  Hi,Sir... for upload and download files from ftp server using servlet and how to use... to disconnect from FTP server " + "after server refused connection. "+e.toString
FTP Server : Create Directory
In this section you will learn how to create directory on FTP server using java
 

 

 

DMCA.com