• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 配置 FTP 服務器以支持 IPv6

    發表于:2007-05-24來源:作者:點擊數: 標簽:服務器配置下一代IPv6ftp
    下一代協議,Internet Protocol version 6 (IPv6),被廣泛認為是 Internet 和 網絡 世界的未來。這種認同已鼓勵各個 IT 公司 開發 支持并使用 IPv6 地址格式進行相互通信的應用程序。在本文中,學習配置 File Transfer Protocol (FTP) 服務器以支持 IPv6,然
    下一代協議,Internet Protocol version 6 (IPv6),被廣泛認為是 Internet 和網絡世界的未來。這種認同已鼓勵各個 IT 公司開發支持并使用 IPv6 地址格式進行相互通信的應用程序。在本文中,學習配置 File Transfer Protocol (FTP) 服務器以支持 IPv6,然后通過一個簡單的使用 IPv6 地址的 Java 程序來與 FTP 服務器通信。

    IPv6,又稱下一代協議,是現有 IPv4 網絡基礎的超集。IPv6 與 IPv4 相兼容和協作,允許您升級您的 Internet 設備。有關 IPv6 的更多信息,請參考我的前一篇文章 “Discover Internet Protocol version 6 (IPv6)”,在 參考資料 部分可以找到這篇文章。

    在本文中,我將向您演示如何在兩種 FTP 服務器上配置 IPv6:Orenosv 1.0(與 Microsoft® Windows® 兼容)和 vsftpd 2.0.1-5(與 Linux® 兼容)。您將使用 IBM® Java™ Runtime Environment (JRE) 1.5.0 來編寫和執行示例 Java 應用程序。

    配置 Windows FTP 服務器 Orenosv 以支持 IPv6

    您可以從 Orenosv 站點(參閱 參考資料下載 Orenosv FTP 服務器。讓我們來看看如何配置服務器來監聽和接受 IPv6 地址。

    首先,下載和安裝服務器,默認安裝在 $Drive/Program Files/Orenosv 中。創建用戶帳戶和其默認目錄。轉到安裝位置,打開 passwd.txt,然后添加下面這一行:

    ipv6:ipv6:/ftpusers/ipv6

    在這一行中,ipv6 代表用戶,ipv6 代表密碼,而 ftpusers/ipv6 表示用戶目錄位置。圖 1 顯示了最終 passwd.txt 文件的樣子。


    圖 1. 最終 passwd.txt 文件表示
    最終 passwd.txt 文件表示

    接著,在 $Install_Location/ftproot 中創建用戶目錄位置 ftpusers/ipv6。最終目錄結構類似于:

    $Install_Location\ftproot\ftpusers\ipv6

    為您創建的 ipv6 用戶提供訪問控制。轉到 $Install_Location,打開 acl.txt,然后添加下面這一行:

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

    最終 acl.txt 文件類似于 圖 2。


    圖 2. 最終 acl.txt 文件表示
    最終 acl.txt 文件表示

    接著,將 ipv6 用戶添加到 admin 組。轉到 $Install_Location,打開 grpdb.txt,然后將用戶添加到 admin 組,類似于:

    admin:admin1,admin2,ipv6

    圖 3 顯示最終 grpdb.txt 文件的樣子。


    圖 3. 最終 grpdb.txt 文件表示
    最終 grpdb.txt 文件表示

    要使 FTP 服務器接受 IPv6 請求,轉到 $Install_Location,然后打開 http.conf。取消注釋 http.conf 文件中的這些行:

    ftp_enable = 1
                ftp_listen = 0.0.0.0@21
                ftp_port_srcport = 20
                

    注釋掉 http.conf 文件中的所有 Secure Sockets Layer (SSL) 條目,然后添加下面這一行以支持 IPv6:

    ftp_listen=IPv6Address@21

    IPv6Address 表示機器 IPv6 地址。這里是一個具有真實 IP 地址的示例:

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

    要重新啟動服務器,導航到 Start > Programs > Orenosv,并單擊 Restart Orenosv Service。檢查 FTP 服務器正在運行并可以監聽 IPv6 請求。為此,打開命令行提示符并使用 IPv6 地址連接 FTP 服務器。如果登錄成功,服務器看上去將與 圖 4 類似。


    圖 4. 成功登錄 FTP 服務器
    登錄 FTP 服務器

    如果登錄失敗,請檢查配置并再試一次。





    回頁首


    配置 Linux FTP 服務器 vsftpd 以支持 IPv6

    vsftpd 服務器默認附帶有 Red Hat Enterprise Linux (RHEL)。讓我們配置服務器來監聽和接受 IPv6 地址。

    首先,以 root 用戶登錄然后打開 vsftpd.conf,該文件通常位于 /etc/vsftpd 目錄中。注釋掉 vsftpd.conf 文件中的下面這一行:

    listen=yes

    將這一行添加到 vsftpd.conf 中以支持 IPv6:

    listen_ipv6=yes

    要重新啟動 vsftpd 服務器,使用 service vsftpd restart 命令。如果重新啟動失敗,請檢查 vsftpd.conf 條目。





    回頁首


    編寫示例 FTP 客戶機程序

    讓我們編寫一個簡單的 Java FTP 客戶機程序來實現下列功能:

    • 使用 IPv6 數字地址連接 FTP 服務器
    • 在與服務器建立連接之后顯示用戶登錄目錄下的文件
    • 提示用戶輸入要下載的文件名
    • 從 FTP 服務器下載各自的文件之后退出

    您可以下載 zip 文件(參閱 下載),其中包含有用來運行程序的所有相關文件的完整代碼;在 運行 Java 應用程序 一節參看更多有關說明。清單 1 解釋程序的核心邏輯。


    清單 1. 從支持 IPv6 的 FTP 服務器獲取文件的示例 Java 程序
    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,"Suclearcase/" target="_blank" >ccessfully 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);
                }
                }
                





    回頁首


    運行 Java 應用程序

    應用程序打包在一個壓縮文件中。解壓縮文件并下載到 SampleAppl 目錄。lib 目錄包含 Java Archive (JAR) 格式的應用程序,還有完整的 Java 源代碼。來自 FTP 服務器的所有文件都下載到 download 目錄。Run.bat 和 Run.sh 文件是特定于操作系統的腳本文件,用于運行應用程序。要運行應用程序,打開 Run.bat(對于 Windows)或 Run.sh(對于 Linux),并編輯這些登錄細節的值:

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

    例如,您的登錄細節可能類似于:

    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"
                

    打開命令行提示符,導航到腳本文件解壓縮的目錄,并執行 Run.bat 或 Run.sh,如 圖 5 所示。


    圖 5. 應用程序輸出信息
    應用程序輸出信息

    在成功登錄之后,應用程序列出文件并提示用戶輸入要下載的文件。本例使用 Welcome.txt。應用程序加載 Welcome.txt,將其放置在 download 目錄,然后退出。

    恭喜!您已成功配置 FTP 服務器以支持 IPv6,并使用 Java 應用程序從 FTP 服務器接收了文件。





    回頁首


    結束語

    您只學習了如何配置和編寫 Java 程序來與啟用 IPv6 的 FTP 服務器通信。您可以運用這些概念來編寫可以與其他啟用 IPv6 的服務器(如 Simple Mail Transfer Protocol (SMTP) 和 Post Office Protocol version 3 (POP3))通信的 Java 應用程序。






    回頁首


    下載

    描述名字大小下載方法
    Sample code for this article wa-ftpipv6-SampleAppl.zip 6KB HTTP

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>