InterSystems FAQ rubric
La procédure de téléchargement à partir d'un serveur FTP est la suivante.
1. Télécharger le fichier image sur le serveur FTP
set tmpfile="c:\temp\test.jpg"
set ftp=##class(%Net.FtpSession).%New()
// connect to FTP server
do ftp.Connect("","<username>","<password>")
// set transfer mode to BINARY
do ftp.Binary()
// Move to the directory to upload
do ftp.SetDirectory("/temp/upload")
// Prepare a stream of files to upload
set file=##class(%File).%New(tmpfile)
do file.Open("UK\BIN\")
// upload file
// 1st argument: File name to create at upload destination
// 2nd argument: File stream to upload
do ftp.Store("test.jpg",file)
// Logout from ftp server
do ftp.Logout()
// close the file
do file.Close()
// (Optional) Delete the uploaded file
//do ##class(%File).Delete(tmpfile)
2. Télécharger le fichier image à partir du serveur FTP
set ftp=##class(%Net.FtpSession).%New() // Connect to ftp server
do ftp.Connect("","<username>","<password>") // Set the transfer mode to BINARY
do ftp.Binary() // Prepare a file stream to download and store
set stream=##class(%FileBinaryStream).%New()
do stream.LinkToFile("c:\temp\testdownload.jpg")
// Go to the download directory
do ftp.SetDirectory("/temp/download") // Download the file and close the stream
do ftp.Retrieve("test.jpg",stream)
do stream.SaveStream()
Set stream="" // Logout from the ftp server
do ftp.Logout()