概要
Qemuではフォルダ共有機能が実質存在しないので、ゲストOSからホストのファイルにアクセスするためのftpサーバーをnode.jsでサクッと構築する。
パッケージのインストール
npm install ftpd
ソース
ftpd.js
varftpd=require('ftpd');varfs=require('fs');varpath=require('path');//コマンドライン引数からポートとルートになるフォルダの設定varport=process.argv[2]||10021;varroot=process.argv[3]||process.cwd();//サーバーの設定varserver=newftpd.FtpServer('127.0.0.1',{//接続後の初期ディレクトリgetInitialCwd:function(){return'/';},//ルートとなるフォルダの設定getRoot:function(){returnroot;},pasvPortRangeStart:1025,pasvPortRangeEnd:1050,tlsOptions:null,allowUnauthorizedTls:true,});//エラーserver.on('error',function(error){console.log('FTP Server error:',error);});//クライアントが接続、認証処理(してるフリ)server.on('client:connected',function(connection){varusername=null;connection.on('command:user',function(user,success,failure){if(user){username=user;success();}else{failure();}});connection.on('command:pass',function(pass,success,failure){if(pass){success(username);}else{failure();}});});//コンソールへの出力を最低限にserver.debugging=0;//指定したポートでサーバー起動server.listen(port);console.log('Listening on port '+port);
Qemuからアクセス
(特に設定をしていなければ)10.0.2.2
でqemuのゲストからホストのサーバーにアクセスできるようです。