当前位置:网站首页>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.
边栏推荐
- 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
- My colleagues quietly told me that flying Book notification can still play like this
- Scala basic tutorial -- 19 -- actor
- [210] usage of PHP delimiter
- Interview summary of large factory Daquan II
- Reptile elementary learning
- Scala基础教程--19--Actor
- Perfect JS event delegation
- Scala基础教程--16--泛型
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
猜你喜欢

输入的查询SQL语句,是如何执行的?

Wireshark packet capturing TLS protocol bar displays version inconsistency

力扣刷题日记/day5/2022.6.27

Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)

Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines

Scala basic tutorial -- 17 -- Collection

Angry bird design based on unity

Neglected problem: test environment configuration management
![[HCIA continuous update] WAN technology](/img/31/8e9ed888d22b15eda5ddcda9b8869b.png)
[HCIA continuous update] WAN technology

力扣刷題日記/day6/6.28
随机推荐
Imitation of numpy 2
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Scala基础教程--20--Akka
2022年字节跳动日常实习面经(抖音)
Scala basic tutorial -- 19 -- actor
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
What types of Thawte wildcard SSL certificates provide
力扣刷题日记/day3/2022.6.25
未来几年中,软件测试的几大趋势是什么?
机器学习概念漂移检测方法(Aporia)
输入的查询SQL语句,是如何执行的?
How is the entered query SQL statement executed?
Mysql5.7 installation tutorial graphic explanation
Basic tutorial of scala -- 16 -- generics
Scala基础教程--19--Actor
Torchdrug tutorial
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
Interview summary of large factory Daquan II