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

 
 


Mayank Soni
JAVA Code for Getting List of Directories and its SubDirectories from FTP server
2 Answer(s)      a year 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

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 Pages:
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
FTP Server : List Files and Directories
In this tutorial we will discuss how to list files and directories on FTP server using java
List all directories on FTP Server
In this section you will learn how to list all the 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
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
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
upload files to apache ftp server - Ajax
(); //A datatype to store responses from the FTP server...) { System.err.println("Unable to disconnect from FTP server... files to apache ftp server. I am using ajax framework for j2ee.Now I am okay
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 Java example
to write code for uploading and downloading the files from FTP server. My FTP... examples of FTP at: FTP Programming in Java tutorials with example code. Thaks...FTP Java example  Where is the FTP Java example on your website? I am
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
Java FTP Client Example
Java FTP Client Example  How to write Java FTP Client Example code? Thanks   Hi, Here is the example code of simple FTP client in Java which downloads image from server FTP Download file example. Thanks
Java FTP Download
Java FTP Download  How to write a program in Java for downloading a file from FTP server? Tell me the good and easy to understand code for Java FTP Download. Thanks   Hi, The easiest way to connect to FTP server
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
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 : Download file
This tutorial contains description of file downloading from the FTP server using java
FTP Server: List all files name
This tutorial represents how to list the entire files name on FTP server using java
FTP server
FTP server  How to store a series of files in a ftp server using java
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
Open Source FTP
ColoradoFTP is the open source Java FTP server. It is fast, reliable and extendable..., 2000 and XP. Open Source FTP Java Library EdtFTPj is the first choice of Java developers worldwide for incorporating FTP functionality
How to upload file on FTP Server
How to upload file on FTP Server  In my application there is a requirement of uploading the file on FTP server. How to upload file on FTP Server... is good and can be used in Java applications. Read FTP File Upload in Java for more
Web Based FTP
, it is not necessary now to install FTP client software in order to download files from... the web based services using several web-based FTP front-end programs and java.... Web-Based FTP works comparatively faster as the web server and the FTP
FTP File Upload in Java
easy to write code for FTP File Upload in Java. I am assuming that you have FTP... will be able to create programs in Java that uploads the file on FTP server... project. Step 2: Write the code that connects to FTP server and uploads the file
FTP Server
This tutorial contains concept of FTP with its features
Java FTP Tutorial
and download files from FTP server on Internet. I have IP address, username and password of the FTP server. Now I have to learn FTP programming in Java fast...Java FTP Tutorial  I am new to FTP programming in Java. I have lots
Java FTP Upload
in Java. View the FTP Server : Upload file example for complete code example...Java FTP Upload  Is there any example code for Java FTP Upload? Which is the easy to use Java FTP Upload example program at roseindia.net? Thanks
Java FTP Connection
if it works? How to make Java FTP Connection to FTP server hosted in my network? Thanks   See the example code at FTP Server : Connect and Login...Java FTP Connection  I am learning to develop a program in Java
Java upload file to ftp
Java upload file to ftp  Hi, How to uploaded file to a ftp server... that uploads files on FTP server. You have to use the Apache FTP client library in your program. Apache FTP Client library can be downloaded from apache website
ftp - Java Beginners
ftp  pls tell me how to connect to a ftp server and copy a file to local machine using java, with UNIX code for copying purpose
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
How to implement FTP using java
want to implement FTP using Java to transfer files and exchange files between FTP client and FTP server. Could anyone help me for How to implement FTP using java... tutorials with example code FTP Server : Connect and Login Apache FTP Server FTP
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
Getting Attributes And its Value
Getting Attributes And its Value   ... to get the attribute and its value from a xml file.  Here is the XML File... and their value from a XML document using the SAX APIs.  Description
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown...;Here is a jsp code that retrieves data from database and display
Java FTP file upload example
; Hi, We have many examples of Java FTP file upload. We are using Apache FTPClient for creating FTP based program in Java. See the complete list of FTP...Java FTP file upload example  Where I can find Java FTP file upload
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 file copy problem? - Java Beginners
-net-1.4.1.jar to copy files from local system to server. Eg: local file name ?test.doc... using for uploading files to server. [code] File f = new File(localfilePath...FTP file copy problem?  Hi, Can any one tell me how to set file
ftp server
ftp server  ftp server
ftp server
ftp server  ftp server
ftp server
ftp server  ftp server
FTP with Java
FTP with Java  How to FTP with Java code? Usually you can find any windows client on internet. You can use FTP software to upload and download files... tutorials at FTP Programming in Java tutorials with example code. Thanks
Java list files
Java list files In this section, you will learn how to display the list of files from a particular directory. Description of code: In the given example, we..., you can display list of files from any directory. Output

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.