当前位置:网站首页>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.FtpSession
Example . - You can choose to set the properties of this instance , To control the general behavior of the session :
Timeout
Timeout specifies wait FTP The time the server replied ( In seconds ).SSLConfiguration
Specifies the active for the connectionSSL/TLS
To configure ( If there is ). IfFTP
Server usage HTTPS, Please use this option .TranslateTable
Specifies the conversion table to use when reading or writing file contents .UsePASV
Enable PASV Pattern .- When
FTP
Server usagehttps
when ,SSLCheckServerIdentity
apply . By default , When%Net.FtpSession
Connect toSSL/TLS
Server 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
CONNECTED
by TRUE, Otherwise FALSE. ReturnCode
Contains the last and FTP Return code when communicating with the server .ReturnMessage
Contains 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.FtpCallback
Subclasses 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
FTP
Conversation time ( Such as “ establish FTP conversation ” Described in ), Set the callback property to a subclass equal to%Net.FtpCallback
.
边栏推荐
- PB的扩展DLL开发(超级篇)(七)
- Machine learning concept drift detection method (Apria)
- 输入的查询SQL语句,是如何执行的?
- 资料下载 丨首届腾讯技术开放日课程精华!
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
- I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
- What if the self incrementing ID of online MySQL is exhausted?
- uni-app与uviewUI实现仿小米商城app(附源码)
- Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
- 奥迪AUDI EDI INVOIC发票报文详解
猜你喜欢
Microservice architecture debate between radical technologists vs Project conservatives
Digital "new" operation and maintenance of energy industry
力扣刷题日记/day7/6.30
Li Kou brush question diary /day4/6.26
被忽视的问题:测试环境配置管理
【uniapp】uniapp开发app在线预览pdf文件
How is the entered query SQL statement executed?
力扣刷题日记/day6/6.28
Scala基础教程--19--Actor
奥迪AUDI EDI INVOIC发票报文详解
随机推荐
李迟2022年6月工作生活总结
Thawte通配符SSL证书提供的类型有哪些
力扣刷题日记/day7/2022.6.29
机器学习概念漂移检测方法(Aporia)
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
激进技术派 vs 项目保守派的微服务架构之争
同事悄悄告诉我,飞书通知还能这样玩
基于NCF的多模块协同实例
Scala基础教程--16--泛型
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
An example of multi module collaboration based on NCF
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
Lua emmylua annotation details
Caché JSON 使用JSON适配器
My colleagues quietly told me that flying Book notification can still play like this
How to improve development quality
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Rookie post station management system based on C language
中国农科院基因组所汪鸿儒课题组诚邀加入
Machine learning concept drift detection method (Apria)