Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Configure FTP servers for IPv6

Learn how to write a Java program that communicates with IPv6-enabled FTP servers

Makham V. Kumar (makhamvk@in.ibm.com), Engineer, IBM, Software Group
Photo of Makham V. Kumar
Makham V. Kumar works with the development team for IBM WebSphere Partner Gateway at IBM India Software Labs. His primary interests are working with the emerging technologies in Java 2 Platform Enterprise Edition (J2EE), the business integration domain, and developing tools based on open source and WebSphere. Makham is an engineer from the University of Karnataka at Belgaum, India.

Summary:  The next-generation protocol, Internet Protocol version 6 (IPv6), is becoming widely accepted as the future of the Internet and networking world. This acceptance has encouraged various IT companies to develop applications that support and talk with each other through the IPv6 address format. In this article, learn to configure the File Transfer Protocol (FTP) server for IPv6, and to communicate with FTP servers through a simple Java program that uses the IPv6 address.

Date:  18 Jul 2006
Level:  Introductory
Also available in:   Chinese

Activity:  16438 views
Comments:  

IPv6, also referred to as the next-generation protocol, is a superset of the existing IPv4 networking foundation. IPv6, which is compatible and interoperable with IPv4, allows you to upgrade your Internet devices. For more information on IPv6, refer to my previous article, "Discover Internet Protocol version 6 (IPv6)," which you can check out in Resources.

In this article, I'll show you how to configure IPv6 for two FTP servers: Orenosv 1.0, which is compatible with Microsoft® Windows®, and vsftpd 2.0.1-5, which is compatible with Linux®. You'll use the IBM® Java™ Runtime Environment (JRE) 1.5.0 to write and execute the sample Java application.

Configuring the Windows FTP server Orenosv for IPv6

You can download the Orenosv FTP server from the Orenosv site (see Resources). Let's see how to configure the server to listen to and accept IPv6 addresses.

First, download and install the server, which will install by default in $Drive/Program Files/Orenosv. Create the user account and its default directory. Go to the installation location, open passwd.txt, and add this line:

ipv6:ipv6:/ftpusers/ipv6

In this line, ipv6 represents the user, ipv6 represents the password, and ftpusers/ipv6 represents the user directory location. Figure 1 shows what the final passwd.txt file looks like.


Figure 1. Final passwd.txt file representation
Final passwd.txt file representation

Next, create the user directory location ftpusers/ipv6 in $Install_Location/ftproot. Your final directory structure looks like this:

$Install_Location\ftproot\ftpusers\ipv6

Provide the Access control for the ipv6 user that you created. Go to $Install_Location, open acl.txt, and add this line:

ftpuser/ipv6/* ALL="_all_" ALL="@admin"

The final acl.txt file looks like Figure 2.


Figure 2. Final acl.txt file representation
Final acl.txt file representation

Next, add the ipv6 user to the admin group. Go to $Install_Location, open grpdb.txt, and add the user to the admin group, like this:

admin:admin1,admin2,ipv6

Figure 3 shows what the final grpdb.txt file looks like.


Figure 3. Final grpdb.txt file representation
Final grpdb.txt file representation

To enable the FTP server to accept IPv6 requests, go to $Install_Location and open http.conf. Uncomment these lines in the http.conf file:

ftp_enable = 1
ftp_listen = 0.0.0.0@21
ftp_port_srcport = 20

Comment all the Secure Sockets Layer (SSL) entries in the http.conf file, and add this line for IPv6 support:

ftp_listen=IPv6Address@21

IPv6Address represents the machine IPv6 address. Here's an example with a real IP address:

ftp_listen = 2002:9b8:708a:0:0:0:0:1@21

To restart the server, navigate to Start > Programs > Orenosv and click Restart Orenosv Service. Check that the FTP server is running and can listen to the IPv6 request. To do this, open the command prompt and connect to the FTP server using the IPv6 address. If your login is successful, it will look like Figure 4.


Figure 4. Successful login to FTP server
Login to FTP server

If the login fails, check the configuration and try again.


Configuring the Linux FTP server vsftpd for IPv6

The vsftpd server comes with Red Hat Enterprise Linux (RHEL) by default. Let's configure the server to listen to and accept IPv6 addresses.

First, login as the root user and open vsftpd.conf, which is usually located in the /etc/vsftpd directory. Comment this line in the vsftpd.conf file:

listen=yes

Add this line for IPv6 support in vsftpd.conf:

listen_ipv6=yes

To restart the vsftpd server, use the service vsftpd restart command. If it fails to restart, check the vsftpd.conf entries.


Writing a sample FTP client program

Let's write a simple Java FTP client program that does the following:

  • Connects to the FTP server using the IPv6 numeric address
  • Displays the files present in the user login directory after establishing a connection to the server
  • Prompts the user to enter the filename to download
  • Exits after downloading the respective file from the FTP server

You can download the zip file (see Downloads), which has the complete code with all the related files to run the program; see more instructions on this in the Running the Java application section. Listing 1 explains the program's core logic.


Listing 1. Sample Java program to get files from FTP server enabled for IPv6
package com.ibm.ipv6.ftp;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;

import sun.net.ftp.FtpClient;

/**
 * @author Makham Kumar
 *
 */
public class IPv6FTPClient extends FtpClient{

    private static final String sourceClass = "IPv6FTPClient";
    private static final String SPACE= " ";
    private static final String SEP = "-";
    private static final String LINE = "\n";

    public IPv6FTPClient(){ }

public static void main(String[] ipv6Main) {
      final String sourceMethod = "main";
      BufferedReader bRead = null;
      IPv6FTPClient ipv6Ins = null;
      String strOption = null;
      String strFileName = null;
      boolean bStatus = true;
	try {
   	      if(ipv6Main.length == 3)
   	      {
   	        ipv6Ins = new IPv6FTPClient();
   	        ipv6Ins.loginToMachine(ipv6Main[0], ipv6Main[1], ipv6Main[2]);
   	        ipv6Ins.listFileSets();
   	        // Capturing details from the user to download files from the FTP server

     	      do {
     	      console(LINE+LINE+SPACE+"Want to download a file ? [Y/N] : ");
              bRead = new BufferedReader(new InputStreamReader(System.in));
              strOption = bRead.readLine();
               if(strOption.equalsIgnoreCase("Y"))
               {
                console(LINE+SPACE+"Enter the file name to download : ");
                strFileName = bRead.readLine();
                bStatus = ipv6Ins.getFile(strFileName);
               }
               else if(strOption.equalsIgnoreCase("N"))
               {
                bStatus = false;
                ipv6Ins.closeServer();
                console(LINE+LINE+SPACE+"Closing the FTP server connection "+LINE);
               }
               else
               {
                bStatus = false;
                console(LINE+LINE+SPACE+"Entered invalid option.");
               }
              } while (bStatus);
               bRead.close();
          }
          else
          {
           console(LINE+"Entered invalid arguments");
          }
           console(LINE+LINE+SPACE+"Application existing !!!"+LINE+LINE);
         }catch(Exception eM)
          {
           eM.printStackTrace();
           console(LINE+"Application existing !!!"+LINE+LINE);
          }
         finally
         {
          try {
            if(bRead != null)
            bRead.close();
           } catch (Exception eFinally) {
            eFinally.printStackTrace();
           }
         }
 }


 /**
  * This utility method connects to FTP server using Username and Password
  * @return void
  */
 private void loginToMachine(String strMachine, String strUser, String strPasswd)
 {
    final String sourceMethod = "loginToMachine";
    try{
      openServer(strMachine);
      login(strUser,strPasswd);
      console(sourceMethod,"Successfully connected to FTP server");
      binary();
    } catch(Exception eLogin)
    {
    eLogin.printStackTrace();
    System.exit(0);
    }
 }


 /**
  * This utility method lists the names of the files in
  * the respective FTP user directory
  * @return void
  */
 private void listFileSets()
 {
    final String sourceMethod = "listFileSets";
    String fileName;
    BufferedReader reader = null;
    try{
        reader = new BufferedReader(new InputStreamReader(list()));
        while ((fileName = reader.readLine()) != null) {
        console(LINE+fileName);
            }
        reader.close();
       }catch(Exception eList)
       {
        eList.printStackTrace();
       }
       finally
       {
        try {
         if(reader != null)
         reader.close();
        }catch (Exception eFinally) {
         eFinally.printStackTrace();
       }
       }
 }


 /**
  * This utility method downloads the file from the FTP server to
  * the location where this Java program is executed
  * @return boolean
  */
 private boolean getFile(String fileName)
 {
    final String sourceMethod = "getFile";
    boolean bStatus = false;
    BufferedInputStream bInputStream = null; 
    FileOutputStream fOutputStream = null;
    String strPath = "."+File.separator+"download"+File.separator;
    try {
        bInputStream = new BufferedInputStream(get(fileName));
        fOutputStream = new FileOutputStream(strPath+fileName);
        int iStart = 0;
        byte[] byteArray = new byte[1024];

        while ((iStart = bInputStream.read(byteArray)) >= 0) {
           fOutputStream.write(byteArray, 0, iStart);
        }
        fOutputStream.close();
        bInputStream.close();
        console(sourceMethod,"Successfully downloaded the file : "+fileName);
        bStatus = true;
        } catch (Exception eGetFile) {
           eGetFile.printStackTrace();
        }
        finally
        {
		 try {
          if(fOutputStream != null)
           fOutputStream.close();
          if(bInputStream != null)
           bInputStream.close();
          } catch (Exception eFinally) {
           eFinally.printStackTrace();
          }
        }
    return bStatus;
  }


 /**
  * This utility method prints the text to console
  * @param String - Source method name
  * @param String - Message text
  * @return void
  */
 private static void console(String sourceMethod, String msgText)
 {
    System.out.println(LINE+SPACE+sourceClass+SEP+sourceMethod+SEP+msgText);
 }


 /**
  * This utility method prints the text to console
  * @param String - Message text
  * @return void
  */
 private static void console(String msgText)
 {
     System.out.print(msgText);
 }

}


Running the Java application

The application is packaged in a compressed file. Unzip the file and download it into the SampleAppl directory. The lib directory contains the application in Java Archive (JAR) format, as well as the complete Java source code. All the files from the FTP server are downloaded into the download directory. The Run.bat and Run.sh files are OS-specific script files that run the application. To run the application, open either Run.bat for Windows or Run.sh for Linux, and edit the values of these login details:

set IPV6ADDRESS="$IPV6_ADDRESS"
set USERID="$USERID"
set PASSWD="$PASSWD"
set JAVA_HOME_15="$JAVA_HOME_15"

For example, your login details might look like this:

set IPV6ADDRESS="2002:9b8:708f:0:0:0:0:1"
set USERID="ipv6"
set PASSWD="ipv6"
set JAVA_HOME_15="C:\Makham\was\wasnd\java"

Open the command prompt, navigate to the directory where the script files are unzipped, and execute Run.bat or Run.sh, as shown in Figure 5.


Figure 5. Application output information
Application output information

After a successful login, the application lists the files and prompts the user to enter the file to download. This example uses Welcome.txt. The application loads Welcome.txt, places it in the download directory, and then exits.

Congratulations! You've successfully configured an FTP server for IPv6 and received files from the FTP server using a Java application.


In conclusion

You just learned how to configure and write a Java program to communicate with IPv6-enabled FTP servers. You can apply these concepts to write Java applications that can communicate with other IPv6-enabled servers, such as Simple Mail Transfer Protocol (SMTP) and Post Office Protocol version 3 (POP3).



Download

DescriptionNameSizeDownload method
Sample code for this articlewa-ftpipv6-SampleAppl.zip6KB HTTP

Information about download methods


Resources

Learn

Get products and technologies

  • IBM trial software: Build your next development project with software available for download directly from developerWorks.

Discuss

About the author

Photo of Makham V. Kumar

Makham V. Kumar works with the development team for IBM WebSphere Partner Gateway at IBM India Software Labs. His primary interests are working with the emerging technologies in Java 2 Platform Enterprise Edition (J2EE), the business integration domain, and developing tools based on open source and WebSphere. Makham is an engineer from the University of Karnataka at Belgaum, India.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Web development, Java technology
ArticleID=146246
ArticleTitle=Configure FTP servers for IPv6
publish-date=07182006
author1-email=makhamvk@in.ibm.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers