当前位置:网站首页>Using FTP
Using FTP
2022-07-04 19:00:00 【User 7741497】
Use FTP
IRIS Provides a class %Net.FtpSession, You can use it from InterSystems IRIS Internal establishment and FTP Server session .
establish FTP conversation
To build FTP conversation , Do the following :
- establish
%Net.FtpSessionExample . - You can choose to set the properties of this instance , To control the general behavior of the session :
TimeoutTimeout specifies wait FTP The time the server replied ( In seconds ).SSLConfigurationSpecifies the active for the connectionSSL/TLSTo configure ( If there is ). IfFTPServer usage HTTPS, Please use this option .TranslateTableSpecifies the conversion table to use when reading or writing file contents .UsePASVEnable PASV Pattern .- When
FTPServer usagehttpswhen ,SSLCheckServerIdentityapply . By default , When%Net.FtpSessionConnect toSSL/TLSServer time , It checks whether the certificate server name matches the name used to connect to the server DNS Name match . If these names do not match , Connection is not allowed .
To disable this check , Please put SSLCheckServerIdentity Property is set to 0.
- call
Connect()Method to connect to a specific FTP The server . - call
ascii()orbinary()Method to set the transmission mode to ASCII Mode or binary mode . To view the current transfer mode , Please check the of the instance Type The value of the property .
Be careful :%Net.FtpSession Each method of returns a state , The status should be checked . These methods also set the values of properties that provide useful information about session state :
- If currently connected , be
CONNECTEDby TRUE, Otherwise FALSE. ReturnCodeContains the last and FTP Return code when communicating with the server .ReturnMessageContains the last and FTP Return message when communicating with the server .
Status() Method returns ( By quoting )FTP The state of the server .
Conversion table of command
%Net.FtpSession stay FTP When viewing the file name and path name on the server , Use RFC 2640 The technology introduced in automatically handles character set conversion . When %Net.FtpSession Connect to FTP Server time , It will use Feat Message to determine whether the server uses UTF-8 character . If it is , It switches the command channel communication to UTF-8, So that all file names and pathnames can be correctly associated with UTF-8 transformation .
If the server does not support FEAT Command or not reported support UTF-8,%Net.FtpSession The instance will use RAW Mode and read or write RAW byte .
In rare cases , If necessary, specify the conversion table to use , Please set up %Net.FtpSession Example of CommandTranslateTable attribute . In general , It should not be necessary to use this property .
FTP File and system methods
Once established FTP conversation , You can call the method of the session instance to execute FTP Mission .%Net.FtpSession Provide the following methods for reading and writing files :
Delete()
Delete file .
Retrieve()
The file from FTP The server is copied to InterSystems IRIS Streaming , And return the stream by reference . To use this stream , Please use the standard flow method :Write()、WriteLine()、Read()、ReadLine()、Rewind()、MoveToEnd() and Clear(). You can also use the of streams Size attribute .
RetryRetrieve()
Allow continued retrieval of files , Because the given stream was last used Retrieve() Created .
Store()
take IRIS The contents of the stream are written to FTP Files on the server .
Append()
Append the contents of the stream to the end of the specified file .
Rename()
Rename file .
Besides ,%Net.FtpSession Provides navigation and modification FTP Method of file system on server :GetDirectory()、SetDirectory()、SetToParentDirectory() and MakeDirectory().
To check the contents of the file system , Please use list() or NameList() Method .
List()Create a stream , It contains a list of all files whose names match the given pattern , And return the stream by reference .NameList()Create an array of file names and return the array by reference .
You can also use ChangeUser() Method changed to another user ; This is faster than logging out and logging in again . Use Logout() Method to log off .
System() Method returns ( By quoting ) About hosting FTP Information about the computer type of the server .
Size() and MDTM() Method returns the size and modification time of the file respectively .
Use generic sendCommand() Method direction FTP The server sends the command and reads the response . This method can be used to send %Net.FtpSession Commands not explicitly supported in .
Upload large files using linked streams
If you want to upload a large file , Consider using a stream interface LinkToFile() Method . in other words , Instead of creating a stream and reading files into it , Instead, create a stream and link it to a file . Calling %Net.FtpSession Of Store() Use this method when linking streams .
Method SendLargeFile(ftp As %Net.FtpSession, dir As %String, filename As %String)
{
Set filestream=##class(%FileBinaryStream).%New()
Set sc=filestream.LinkToFile(dir_filename)
If $$$ISERR(sc) {do $System.Status.DisplayError(sc) quit }
// The uploaded file will have the same name as the original file
Set newname=filename
Set sc=ftp.Store(newname,filestream)
If $$$ISERR(sc) {do $System.Status.DisplayError(sc) quit }
}Customize FTP Callback from the server
You can customize FTP Callback generated by the server . for example , By doing so , You can provide the user with an indication that the server is still processing large transfers , Or allow the user to abort the transmission .
To customize FTP Callback , Do the following :
- establish
%Net.FtpCallbackSubclasses of . - In this subclass , Realization
RetrieveCallback()Method , The method starts from FTP The server calls... Periodically when it receives data . - We need to achieve
StoreCallback()Method , Writing data to FTP This method is called periodically when the server is running . - establish
FTPConversation time ( Such as “ establish FTP conversation ” Described in ), Set the callback property to a subclass equal to%Net.FtpCallback.
边栏推荐
- 力扣刷题日记/day3/2022.6.25
- [cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
- Scala basic tutorial -- 15 -- recursion
- fopen、fread、fwrite、fseek 的文件处理示例
- Android uses sqliteopenhelper to flash back
- 删除二叉搜索树中的节点附图详解
- I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
- 【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
- Halcon template matching
- Li Kou brush question diary /day5/2022.6.27
猜你喜欢

Mysql5.7 installation tutorial graphic explanation

ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development

力扣刷题日记/day2/2022.6.24

提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习

Rookie post station management system based on C language

Digital "new" operation and maintenance of energy industry

Li Kou brush question diary /day2/2022.6.24
![[HCIA continuous update] network management and operation and maintenance](/img/a4/406b145793b701b001f04c7538dab3.png)
[HCIA continuous update] network management and operation and maintenance
随机推荐
[go ~ 0 to 1] read, write and create files on the sixth day
Machine learning concept drift detection method (Apria)
LD_ LIBRARY_ Path environment variable setting
How to open an account is safe,
[HCIA continuous update] WAN technology
MXNet对GoogLeNet的实现(并行连结网络)
一、C语言入门基础
力扣刷题日记/day1/2022.6.23
Torchdrug tutorial
Pb extended DLL development (super chapter) (VII)
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
如何使用 wget 和 curl 下载文件
发送和接收IBM WebSphere MQ消息
Mysql5.7 installation tutorial graphic explanation
C language printing exercise
力扣刷题日记/day7/6.30
How to improve development quality
Scala基础教程--14--隐式转换
[211] go handles the detailed documents of Excel library
Li Kou brush question diary /day3/2022.6.25