コマンドライン(IIS)からFTPを構成する

ここから始めたIISコマンドラインの研究を続けて、IISでFTPを構成する方法を理解することを提案します。

バージョン7以降、IISはユニバーサルコマンドラインツールAppCmdを導入しました。 これで、Webサイトで(IIS 7から)できるようになったのとまったく同じ方法で、コマンドラインからFTPサービスを作成、構成、使用できます。 例をさらに詳しく見てみましょう。



FTPをインストールする



まず、必要なコンポーネントをインストールする必要があります。 既にIISがプリインストールされており、FTPサービスのみが必要であるとします。 pkgmgrパッケージマネージャーを使用します。

pkgmgr /iu:IIS-FTPServer;IIS-FTPSvc;IIS-FTPExtensibility;
      
      







FTPを構成する



これで、IISは最初のFTPを構成する準備ができました。 AppCmdを使用するには、コマンドへのフルパスを使用する必要があります:%windir%\ system32 \ inetsrv \ appcmd.exe、またはPATH環境変数へのパスを記述します。 ディレクトリから直接appcmdを実行するだけで十分です。



 cd %windir%\system32\inetsrv set ftproot=%systemdrive%\inetpub\ftproot set ftpsite=MyFtp if not exist "%ftproot%" (mkdir "%ftproot%") appcmd add site /name:%ftpsite% /bindings:ftp://*:21 /physicalpath:"%ftproot%" appcmd set config -section:system.applicationHost/sites /[name='%ftpsite%'].ftpServer.security.authentication.AnonimouseAuthentication.enabled:true appcmd set config -section:system.applicationHost/sites /[name='%ftpsite%'].ftpServer.security.ssl.controlChannelPolicy:"SslAllow" appcmd set config -section:system.applicationHost/sites /[name='%ftpsite%'].ftpServer.security.ssl.dataChannelPolicy:"SslAllow" appcmd set config -section:system.applicationHost/sites /[name='%ftpsite%'].ftpServer.directoryBrowse.showFlags:DisplayVirtualDirectories appcmd set config -section:system.applicationHost/sites /[name='%ftpsite%'].ftpServer.userIsolation.mode:StartInUsersDirectory appcmd set config %ftpsite% /section:system.ftpserver/security/authorization /+[accessType='Allow',permissions='Read',roles='',users='*'] /commit:apphost
      
      





このスクリプトは、システムドライブにinetpub\ftproot



を作成し、MyFtpサイトのルートフォルダーにアタッチします。 また、匿名認証を使用するようにサイトを構成しました。 また、SSLを許可モードにします(デフォルトでは必須です)。 最後の行では、すべてのユーザーに読み取り許可を配布しました。 ここで、サイトに仮想フォルダーを追加するだけで使用できます。showFlags:DisplayVirtualDirectoriesパラメーターを使用すると、ルートディレクトリだけでなく仮想ディレクトリも表示できます。

したがって、ディレクトリを追加します。

 appcmd add vdir /app.name:"%ftpsite%/" /path:/path1 /physicalPath:D:\path1 appcmd add vdir /app.name:"%ftpsite%/" /path:/path2 /physicalPath:\\MEDIASERVER\path2
      
      







確認する



確認するには、コマンドラインとftpコマンドも使用します。

 c:\Users\User>ftp server Connected to SERVER.domain.corp. 220 Microsoft FTP Service User (SERVER.domain.corp:(none)): anonymous 331 Anonymous access allowed, send identity (e-mail name) as password. Password: 230-User logged in. Win32 error: The operation completed successfully. Error details: File system returned an error. 230 End ftp> dir 200 EPRT command successful. 125 Data connection already open; Transfer starting. 06-01-12 04:33PM <DIR> path1 06-01-12 04:33PM <DIR> path2 226 Transfer complete. ftp: 93 bytes received in 0,00Seconds 93000,00Kbytes/sec. ftp>
      
      







PowerShellを使用しない理由



PowerShell用のスクリプトを作成するには、いくつかのマイナーな外観の変更が必要です。

したがって、FTPサービスをインストールするには、以下を行う必要があります。

 Add-WindowsFeature Web-Ftp-Server,Web-Ftp-Service,Web-Ftp-Ext
      
      





FTPサイトを作成するには:



 $ftproot="$env:systemdrive\inetpub\ftproot" $ftpsite="MyFtp" if (-not (test-path $ftproot)){ new-item -path $ftproot -type directory } new-item -path IIS:/sites/$ftpsite -type site -bindings @{protocol='ftp';bindingInformation=':21:'} -physicalpath:$ftproot
      
      







同様に、仮想ディレクトリを追加できます。

 new-item -path IIS:/sites/$ftpsite/path1 -type virtualdirectory -physicalpath d:\share
      
      





しかし、わかりやすいソリューションの構成で作業するためのソリューションは見つかりませんでした。 ここここで見つけすべて。 後者は、APPHOSTレベルでいくつかの変更を行う必要があるという事実に照らして私を刺激しませんでした。

提案やコメントがある場合-常に歓迎します。 喜んで追加します。



All Articles