當你有大於 1GB 的資料要在網路上傳輸, 利用現有大部份的 httpd, ftpd 等伺服器都沒辦法識別傳輸這類大檔案。 假設大檔案位於本地端 source@localhost 帳號下,你要傳輸到遠地端 destination@remotehost 帳號下。 則你可以使用如下任一方法: 其中,port_num 為 ssh 的 tcp 連線埠號,預設值為22。 path/from/file 為 source@localhost 帳號下的大檔案。 path/to/file 為 destination@remotehost 帳號下打算存放大檔案的位置 A.利用sftp remotehost> sftp -oPort=port_num source@localhost:path/from/file B.利用scp remotehost> scp -P port_num source@localhost:path/from/file path/to/file 或 localhost> scp -P port_num path/from/file destination@remotehost:path/to/file C.利用rsync+ssh,具續傳功能,不怕中途斷線 remotehost> rsync --copy-links --progress --partial --append -vtpre 'ssh -p port_num ' source@localhost:path/from/file path/to/file 或 localhost> rsync --copy-links --progress --partial --append -vtpre 'ssh -p port_num ' path/from/file destination@remotehost:path/to/file 上述3方法適用於 Linux 或 Cygwin 平台。 尤其最後一個方法的 rsync 支援中斷續傳功能,很適合大資料夾之傳輸。 註: 1.若只想在本機硬碟之間進行大量資料夾之備份,也可使用如下 rsync 語法,只要少掉 e 參數即: $ rsync --stats --progress --partial --append -vtpr path/from/folder/ path/to/folder/ 2.rsync 參數說明: rsync source@localhost:path/from/folder/ destination@remotehost:path/to/folder/ --copy-links 將符號連結(軟連結或捷徑)進行實體拷貝 --progress 顯示傳輸進度 --stats 顯示檔案統計資訊 --partial 傳輸中斷時,去處端將留下接收一半的檔案 --append 傳輸時,遇到去處端長度有較小的檔案將自動從來源端補齊剩餘長度 --rsync-path="sudo rsync" 讓遠方切換特權模式,取得特權目錄內容 -v 傳輸時列印檔名訊息 -t 去處端維持來源端的修改時間 -p 去處端維持來源端的存取權限 -r 傳輸包含所有子資料夾 -e 'ssh -p port_num' 利用後面的指令字串進出連線傳輸 -n 乾跑,只看清單,不實際拷貝 3.如果整理重複目錄時,只想找出本機硬碟之間兩目錄的差異, 可自訂如下批次檔 ~/bin/backup.sh: #!/bin/bash # #rsync --stats -hlPrtv source/ destin/ # [P]: keep (partial)ly transferred files, show (progress) during transfer # [h]: output numbers in (human-readable) format # [l]: copy sym(links) as symlinks readable # [r]: get (recursive) into directories # [t]: preserve modification (times) # [v]: increase (verbose) level echo "rsync --stats --append --partial --progress -vtprn $*" rsync --stats --append --partial --progress -vtprn $* 實際比對時,可利用如下指令, host> bash ~/bin/backup.sh source_path/ destin_path/ 得到source_path/須要搬動到destin_path/的檔案清單。 搬完後,source_path/ 目錄將完全包含於 destin_path/ 目錄,也就是 前者有的後者必有,故前者目錄即使刪除也沒關係。 又因為有參數-n,執行結果只列印差異,沒有實際搬動。 故當兩者差異為0檔案,無須搬動,即可確認前目錄已完全同步到後目錄。 這時就可安心刪除前目錄。
2010年10月20日 星期三
transfer over 1gb large files over internet via ssh
2010年9月17日 星期五
transfer from zte f188 cellphone to vista via bluetooth
zte f188手機使用藍牙傳輸檔案給vista電腦方法
如下先讓vista電腦及zte f188手機互相識別對方裝置存在
然後開始將手機資料傳到電腦:
A.ZTE F188手機:如下先發出信號,待對方補捉
[選單/電子祕書/連結/藍牙/藍牙管理器]
啟動藍牙
顯示手機
手機名稱:F188
B.VISTA電腦:如下接收信號,產生密碼,待對方確認
Bluetooth裝置/檢視/名稱
可看到F188
按下後,將電腦產生的一組密碼,輸入到手機密碼欄中
手機中將出現電腦裝置名:vista
C.開始手機往電腦傳輸
電腦先左鍵按Bluetooth裝置/接收檔案
手機再選到檔案後,選擇[發送/藍牙],即可傳送過去
2010年1月19日 星期二
combination enumerator in java
-
- /*
- Combination.java
-
- generates all combinations of C(n,m) for n >= m >= 0
-
- Usage: java Combination n m
-
- Sample Output:
- > java Combination 5 2
- --- recursive one-shot generation ---
- k=1 ---> {1, 2}
- k=2 ---> {1, 3}
- k=3 ---> {1, 4}
- k=4 ---> {1, 5}
- k=5 ---> {2, 3}
- k=6 ---> {2, 4}
- k=7 ---> {2, 5}
- k=8 ---> {3, 4}
- k=9 ---> {3, 5}
- k=10 ---> {4, 5}
- --- nonrecursive item-wise generation ---
- k=1 ---> {1, 2}
- k=2 ---> {1, 3}
- k=3 ---> {1, 4}
- k=4 ---> {1, 5}
- k=5 ---> {2, 3}
- k=6 ---> {2, 4}
- k=7 ---> {2, 5}
- k=8 ---> {3, 4}
- k=9 ---> {3, 5}
- k=10 ---> {4, 5}
-
- --- Combination.java ---
- */
- import java.util.Vector;
- import java.util.Enumeration;
-
- // class for generating all m-item selection sets from an n-item population set
- public class Combination {
- Vector < Object > n_set; // population set of objects for combination
- int n; // population size, n >= m >= 0
- int m; // selection size
-
- // constructor for combination object
- // n_set: population set of objects for combination
- // m: selection size
- public Combination(Vector < Object > n_set, int m) {
- this.n_set = n_set;
- this.n = n_set.size();
- this.m = m;
-
- if (n < m || m < 0 || n <= 0) {
- System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
- }
- }
-
- // generate integer objects from 1 to n
- public static Vector < Object > generateIntegers(int n) {
- Vector < Object > set = new Vector < Object > ();
- for (int i = 1; i <= n; i++) set.add(i);
- return set;
- }
-
- // generate integer objects from 1 to n
- public static Vector < Vector < Object >> cnm(int n, int m) {
- Vector < Object > set = generateIntegers(n);
- Combination c = new Combination(set, m);
- Vector < Vector < Object >> set_list = c.cnm();
- return set_list;
- }
-
- // generate all m-item selection sets from population set n_set
- // returns set of all m-item selection sets from population set n_set
- Vector < Vector < Object >> cnm() {
- return cnm(n_set, m);
- }
-
- // recursive generation of all m-item selection sets from population set n_set
- // n_set: population set
- // m: selection size
- // returns set of all m-item selection sets from population set n_set
- Vector < Vector < Object >> cnm(Vector < Object > n_set, int m) {
- Vector < Object > set = new Vector < Object > ();
- Vector < Vector < Object >> result_list = new Vector < Vector < Object >> ();
-
- int n = n_set.size();
- if (n < m || m < 0 || n <= 0) {
- System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
- return null;
- }
-
- // base case 1: m=0
- if (m == 0) {
- result_list.add(set);
- return result_list;
- }
- // base case 2: m=n
- else if (m == n) {
- result_list.add(n_set);
- return result_list;
- }
-
- // recursive call:
- Vector < Vector < Object >> result_with_first = new Vector < Vector < Object >> ();
- Vector < Vector < Object >> result_without_first = new Vector < Vector < Object >> ();
-
- Vector < Object > n_minus_1_set = new Vector < Object > (n_set);
- n_minus_1_set.removeElementAt(0);
- result_with_first = cnm(n_minus_1_set, m - 1);
- result_without_first = cnm(n_minus_1_set, m);
- for (Vector < Object > comb: result_with_first) {
- comb.insertElementAt(n_set.firstElement(), 0);
- }
-
- result_list.addAll(result_with_first);
- result_list.addAll(result_without_first);
-
- return result_list;
- }
-
- // get enumerator for all m-item selection sets from population set n_set
- Enumeration < Vector < Object >> enumeration() {
- if (n < m || m < 0 || n <= 0) {
- System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
- return null;
- }
- return new Enumerator();
- }
-
- // inner class of Combination class
- // enumerator for non-recursive generation of all m-item selection sets from population set n_set
- public class Enumerator implements Enumeration < Vector < Object >> {
- int index[];
- int index_upper[];
- boolean carry;
- boolean hasMore;
- Vector < Object > element;
-
- // constructor for m-item selection set enumerator
- public Enumerator() {
- element = new Vector < Object > ();
- hasMore = true;
-
- //carry = new boolean[m];
- index = new int[m];
- index_upper = new int[m];
- for (int i = 0; i <= m - 1; i++) {
- index[i] = i;
- index_upper[i] = n - m + i;
- }
- }
-
- public boolean hasMoreElements() {
- return hasMore;
- }
-
- public Vector < Object > nextElement() {
- int i;
- element.clear();
- for (i = 0; i <= m - 1; i++) {
- element.add(n_set.get(index[i]));
- }
-
- // point to next index
- carry = false;
- for (i = m - 1; i >= 0; i--) {
- int digit = index[i];
- if (digit + 1 <= index_upper[i]) {
- index[i]++;
-
- if (carry == true)
- while (i + 1 <= m - 1) {
- index[i + 1] = index[i] + 1;
- i++;
- }
- break;
- } else
- carry = true;
- }
-
- if (i < 0) hasMore = false;
- return element;
- } // end of nextElement
- } // end of enumerator class
-
- // main program for test
- public static void main(String args[]) {
- int n = 5;
- int m = 2;
-
- if (args.length == 2) {
- n = Integer.parseInt(args[0]);
- m = Integer.parseInt(args[1]);
- }
-
- System.out.println("--- recursive one-shot generation ---");
-
- Vector < Vector < Object >> set_list = Combination.cnm(n, m);
- int k = 1;
- for (Vector < Object > set: set_list) {
- System.out.printf("k=%d ---> {", k);
- boolean first = true;
- for (Object o: set) {
- if (first) first = false;
- else System.out.print(", ");
- System.out.print((Integer) o);
- }
- System.out.println("}");
- k++;
- }
-
- System.out.println("--- nonrecursive item-wise generation ---");
-
- Vector < Object > set = Combination.generateIntegers(n);
- Combination c = new Combination(set, m);
- Enumeration < Vector < Object >> e = c.enumeration();
- k = 1;
- while (e.hasMoreElements()) {
- set = e.nextElement();
- System.out.printf("k=%d ---> {", k);
- boolean first = true;
- for (Object o: set) {
- if (first) first = false;
- else System.out.print(", ");
- System.out.print((Integer) o);
- }
- System.out.println("}");
- k++;
- }
- }
- }
註: 本程式使用 GitHub JavaScript code prettifier 工具標示顏色。其方法如下:
1.參考 [Blogger] 如何在 Blogger 顯示程式碼 - Google Code Prettify
於【Blogger 版面配置 HTML/JavaScript小工具】安裝如下套件
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
2.文章編輯再以HTML模式為程式包上如下標籤。
<code class="prettyprint lang-java linenums"> ... </code>
訂閱:
文章 (Atom)