Published on InterSystems Developer Community (https://community.intersystems.com)

ホーム > %Net.FtpSession クラスを使用してファイルサイズを取得する方法

記事
Hiroshi Sato · 2021年10月12日 2m read

%Net.FtpSession クラスを使用してファイルサイズを取得する方法

これはInterSystems FAQ サイトの記事です。

ファイルサイズを取得する専用メソッドはありませんが、%Net.FtpSession クラスの sendCommand() メソッドを通してFTPのSIZEコマンドを呼び出し、サイズを取得できます。

簡単な利用例をご紹介します。

まず、以下の様なクラスを定義します。

Class MyNet.FtpSession Extends %Net.FtpSession
{ Method getSize(fname As %String, ByRef size As %Integer)
{
set type=..Type  // 現Typeを保存しておく
do ..Binary()
set st=..sendCommand("SIZE "_fname) //SIZE <file name>
set size=..ReturnMessage
if type="Ascii" {
do ..Ascii()
}
quit
} }

上記で作成したクラスを使用したサンプルコードです。 

 set ftp=##class(MyNet.FtpSession).%New()
 write ftp.Connect(ftpsrv,user,pass)  // FTPサイトへ接続ができると1が返ります。
 do ftp.getSize(fname,.fsize)         // 第2パラメータに指定したファイルのサイズが返ります
 write "ファイルサイズ : ",fsize,!
 write ftp.Logout()                   // 成功したら1が返ります

 

※ sendCommand() メソッドは [Internal] 属性が付与されているため将来変更される可能性があります。

#ヒントとコツ #Caché #Ensemble #InterSystems IRIS #InterSystems IRIS for Health

ソースURL:https://jp.community.intersystems.com/post/netftpsession-%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%B5%E3%82%A4%E3%82%BA%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95