[WWW] FTP 的主動模式( active )和被動模式( passive )

這一篇轉錄自 http://forum.icst.org.tw/phpBB2/viewtopic.php?t=79 目前 FTP 已經是大家必備的東西,那架站之前你必須先瞭解什麼是 主動模式( active )和被動模式( passive ) FTP 的主動模式( active )和被動模式( passive ) FTP 是一種檔傳輸協定 (File Transfer Protocol),它的連線模式有兩種﹕ 主動模式( active )和被動模式( passive )。以下說明 FTP 的連線是怎樣建立的﹕ 在 active 模式下 (一般預設的模式)﹕ 1. FTP client 開啟一個隨機選擇的TCP port 呼叫 FTP server 的 port 21請求連線。當順 利完成 Three-Way Handshake 之後,連線就成功建立,但這僅是命令通道的建立 。 2.當兩端需要傳送資料的時候,client 透過命令通道用一個 port command 告訴 server ,client可以用另一個TCP port 做數據通道。 3.然後 server 用 port 20 和剛才 client 所告知的 TCP port 建立數據連線。請注意:連 線方向這是從 server 到 client 的,TCP 封包會有一個 SYN flag。 4. [Read More]

[Java] 正規取代表示法

最近弄國科會計畫,所以都在碰 java 的東西,都在弄 sparqlrdf 的東西,昨天弄懂一些基本的 sparql,然而利用 sarql 語法取出來的數值不是我想要的,所以利用正規表示,把字串取代了。 我想取代的字串如下:

( ?url = “LAB221″^^xsd:string ) 我只想要中間的 LAB221 的部份,然後我上網找了方法,總共可以使用兩種方法 第一種

String result = "( ?url = \"LAB221\"^^xsd:string )";
// compile pattern
Pattern p = Pattern.compile("[^\"]+\"([^\"]+)\"[^\"]+");

// get matcher
Matcher m = p.matcher(result.replaceAll("[

  • ]","")); // test if match if (m.matches()) { System.out.println(m.group(1)); } else { System.out.println("error"); } /* 正規比對 */
    上面感謝 ptt qrtt1 給我的一點啟示 [Read More]

    [生活日記] 中正電機通訊網路組花圃

    上禮拜五跟這裡拜五整理了一下花圃,因為這花圃是大家網路組共同維護的,但是目前是由我的老師負責維護,好像其他老師都不太會管這方面的事情,所以我們老師很熱心的每個禮拜都跟我們一起整理花圃,這學期呢,交接給我們碩一這群學生,不過現在還是只有我們老師的學生下來整理花圃,希望以後可以號招更多人下來幫忙,底下就是我們的花圃照片 Click to view full size image 宗翰在整理花圃 Click to view full size image 我們的花圃跟後面的不太一樣吧,我們的比較整齊 Click to view full size image 我的老師在那邊整理,哈哈,被我偷拍

    [Read More]

    [Ubuntu] 安裝 apache php5 遇到的問題

    很奇怪的,今天在安裝 apache2 跟 php5 想說很簡單,可是安裝好,寫測試檔測試的時候,發現當會變成下載 php5 的檔案,然後我看了一下 apache2.conf 觀察到如下 AddType application/x-httpd-php .php .phtml .php3 AddType application/x-httpd-php-source .phps LoadModule php5_module /usr/lib/apache2/modules/libphp5.so 然後我去 /usr/lib/apache2/modules/ 底下看,也有看到 libphp5.so 這個檔案,但是就是不能執行 php,後來在 ubuntu 官網找到解答,解答方法如下

    檢查 /etc/apache2/mods-enabled 內有沒有php5.conf , php5.load若沒有, 請 sudo a2enmod php5 重新啟動 apahce2 sudo /etc/init.d/apache2 restart http://www.ubuntu.org.tw/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=5298&forum=9

    [phpBB2] 2.0.22 -> 2.0.23 安全性修正版本釋出

    我在竹貓星球看到這個消息的,自己本身有在玩 phpBB2 的系統,其實這套是我學 php 的開始,當初架設漫畫網站,就是提供給大家一個漫畫平台,不過後來倒了,因為自己 php 功力沒有像今天有基本的基礎,所以就沒在繼續經營了,不過我想這不會影響我用 phpBB 這套免費的系統,然而我還在這系統開發跟 Gene6 FTP Server 整合的外掛,自己無聊亂寫的,不過這不是正題,底下就是轉錄自竹貓星球的文章。 [Fix] Correctly re-assign group moderator on user deletion (Bug #280) [Fix] Deleting a forum with multiple polls included (Bug #6740) [Fix] Fixed postgresql query for obtaining group moderator in groupcp.php (Bug #6550) [Fix] Selected field on first entry by default for font size within posting_body.tpl (Bug #7124) [Fix] Adjusted maxlength parameters in admin/styles_edit_body.tpl (Bug #81) [Fix] Fixed html output in make_forum_select if no forums present (Bug #436) [Fix] Fixed spelling error(s) in lang_admin. [Read More]

    [Java] 判斷字串是否是整數

    有時候必須知道輸入的字串是否是整數,如果不是的話,就要重新輸入,這有兩種作法 第一種是使用 try … catch … finally 的方法,如下

    public class test
    { 
    	public static void main(String args[])
      {
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); 
        try{
          System.out.print("請輸入你要的數字:");
          int test = Integer.parseInt(buf.readLine()); 
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
          System.out.println(e.toString() + "陣列程式發生錯誤");  
        }
        catch(ArithmeticException e)
        {
          System.out.println(e.toString() + "數學發生錯誤");  
        }
        catch(Exception e)
        {
          System.out.println(e.toString() + "程式發生錯誤");
        }
        finally
        {
          System.out.println("執行成功");  
        }
    	
      }
    }
    
    另外一種方法,是利用 while 然後利用 Character.isDigit 的方法 [Read More]

    [中正大學] 上課無聊拍

    這是載我生日的當天上課被拍的,雖然大家都不知道我生日,所以我要低調阿,這學期這堂課第一次上課,宗翰拿著我的手機亂拍,照片如下 Click to view full size image 這是後面吧~ Click to view full size image 這張是側面,我發現我不管哪一面都還不錯阿,哈哈 Click to view full size image 這是我朋友小夢,哈哈,裝啥鬼臉 Click to view full size image 宗翰的手機吊飾 Click to view full size image 我喝水的瓶子

    [java] 在 linux 底下使用 java 來執行 Linux 指令

    其實可以在 linux 底下去寫 shell script 然後去執行 java 程式,而並非用 java 去執行 Linux 指令,不過java也是可以做到執行 shell command,底下就是我寫的 java 測試 code,去列出自己所在的目錄底下的檔案 ls 這個指令

    import java.io.*;
    import java.net.*;
    import java.util.*;
    
    public class runstart{
            public static void main(String a[]) throws Exception{
                    Process pl = Runtime.getRuntime().exec("/bin/ls");
                    String line = "";
                    BufferedReader p_in = new BufferedReader(new InputStreamReader(pl.getInputStream()));
                    while((line = p_in.readLine()) != null){
                            System.out.println(line);
                    }
                    p_in.close();
            }
    }
    
    參考

    http://debut.cis.nctu.edu.tw/~ching/Course/JavaCourse/05_input_output/02_input_output.htm

    [C/C++] 判斷字串是否為數字

    常常在寫 C 語言,有時候想判斷輸入的是否為數字,如果不是的話,要重新輸入,所以寫一下怎麼判斷的,ptt提供了下面很多函式

    isalnum ctype.h 測試某一整數值是否為’A’-‘Z’,’a’-‘z’,’0′-‘9’等文數字之一。 isalpha ctype.h 測試某一整數值是否為’A’-‘Z’,’a’-‘z’,等字母之一。 isascii ctype.h 如果ch的值判於0-127,則傳回非零整數(0x00-0x7F)。 iscntrl ctype.h 如果ch是一刪除字元或一般控制字元,則傳回非零整數(0x7F或0x00-0x1F)。 isdigit ctype.h 如果ch是一數字,則傳回非零整數。 isgraph ctype.h 如果ch是為可列印字元,則傳回非零整數。 islower ctype.h ch若為小寫字母,則傳回非零整數。 isprint ctype.h ch若為可列印字元,則傳回非零整數。其功能與isgraph相似。 ispunct ctype.h ch若為標點符號,則傳回非零整數。 isspace ctype.h ch若為空白字元或定位字元(Tab),歸位字元(Enter鍵),新列字元,垂直定位字元,換頁字元,則傳回非零整數。 isupper ctype.h ch若為大寫字母,則傳回非零整數。 isxdigit ctype.h ch若為一個十六進位數字,則傳回非零整數 用程式去判斷會更快,因為上面的函式,都是要單一字元去檢查,非常不方便,所以就寫了底下的程式

    [Read More]

    [C/C++] 判斷年份是否閏年

    無聊幫同學寫作業,其實這還蠻簡單的,判斷閏年的方法如下 1、可以被4整除但不可以被100整除。 2、可以被400整除。 程式碼如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include <stdio.h> #include <string.h> #include <stdlib.h> int leap(int year); int leap(int year) { if((year%4)==0 && (year%100)!=0 || (year%400) ==0) { printf ("%d是閏年\n",year); } else { printf ("%d不是閏年\n",year); } } int main(int argc,char *argv[]) { char *p; char year[20]; printf("請輸入您要查詢的年份『輸入exit離開』: "); while(fgets(year, sizeof(year), stdin)) { if ((p = strchr(year, '\n')) ! [Read More]