2018/01/09

Windows と Linux 間でちょっとしたファイル転送をしたいと思った時に msys2 の ssh コマンドや WinSCP が入ってなくて、さらにレジストリなどを汚したくない環境で手軽に使える使えるファイル転送ソフトが欲しかった。Linux 側から Samba で繋いでも良いんだけど、その用途の為だけに Samba いれたくないなと思ったのでバイナリを1個ポンとコピーすれば使える物を作った。

GitHub - mattn/ft

ft is CLI tool that transfer files.

https://github.com/mattn/ft

使うには両方の端末に ft というコマンドがインストールされている必要がある。「Go が入れられるなら msys2 も(ry」とか言われてしまいそうだけど、実際にそういう環境や要件ってあるのですよ。はい。

Go で書いたので go get が出来る環境ならば1発でインストール出来ます。使い方は、ファイルを送りたい側が

$ ft serve

を実行し、受け取りたい側が

$ ft download -a 192.168.123.4

の様に実行する。serve を実行した側のカレントディレクトリ配下が download を実行したカレントディレクトリ配下に転送される。

仕組みは gRPC のストリーム API で作られている。一つはファイルの一覧を返す ListFiles、もう一つはバイナリを転送する為の Download というインタフェース。

syntax = "proto3";

//google.protobuf.Timestamp
//import google_protobuf "github.com/golang/protobuf/ptypes/timestamp";
import "google/protobuf/timestamp.proto";

package proto;

service FileTransferService {
  rpc ListFiles(ListRequestType) returns (stream ListResponseType) {};
  rpc Download(DownloadRequestType) returns (stream DownloadResponseType) {};
}

message ListRequestType {
}

message ListResponseType {
  string name = 1;
  int64 size = 2;
  uint32 mode = 3;
  google.protobuf.Timestamp modTime = 4
}

message DownloadRequestType {
  string name = 1;
}

message DownloadResponseType {
  bytes data = 1;
}

Download もストリームになっているのでデカいファイルでも転送出来ます。通信は gRPC のレベルで圧縮されます。現状は in-secure になっているけど、今後 secure オプションも付けていきたいと思う。TLS 通信をサポートしています。

Posted at 10:26 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.