NodeJSからFTPするのに日本語が使えないことに気づいた。 どうにも上っ面の対応じゃだめで、大元のパッケージに手を入れました。 3〜4行直しただけなんだけど、ついでにGitHubにフォークしておきました。
https://github.com/tomohiroorikasa/node-ftp
パラメータに fileEncoding を追加しています。 node-ftpの代わりにインストールしておいて、以下のような感じで使います。 (CoffeeScript)
PromiseFtp = require 'promise-ftp'
co () ->
connect =
host: '[hostname or IPaddress]'
port: 21
user: '[user]'
fileEncoding: 'UTF8' # <- ここ
secure: false
ftp = new PromiseFtp()
try
yield ftp.connect connect
catch e
console.error 'connected faild'
throw e
yield ftp.binary
yield ftp.list( 'Remote Root Path' )
⋮
⋮
⋮ 処理をここに
⋮
⋮
.then ( ret ) ->
if ret && ret != ''
console.log ret
process.exit 0
,( err ) ->
console.error 'err:', err
process.exit 1
GitHubのフォークの仕方がいまいちよくわからない。 ブランチ切らずにあげてみたけど、これで合ってるのかどうか。 怒られないかちょっと心配…w