FTP Server'larla ÇalışmaWorking with FTP Servers

This page is part of an incremental translation project. Body text not yet translated to Turkish falls back to English even in TR mode.

TROIA Platformu, application server ve file server arasında dosya transfer operation'larını destekler. Bu bölüm, ftp operation'larını ve ilgili komutları tanıtmayı amaçlar.TROIA Platform supports file transfer operations between application server and file server. This section aims to introduce ftp operations and related commands.

GirişIntroduction

FTP Operation'ları, Secure File Transfer Protocol'de (SFTP veya SSH File Transfer Protocol olarak da bilinir), FTP'de (File Transfer Protocol olarak da bilinir), FTPS'de (File Transfer Protocol SSL) 5.01.04 041203'ten sonraki build'lerde desteklenir.FTP Operations are supported on builds after after 5.01.04 041203 in Secure File Transfer Protocol (also known as SFTP or SSH File Transfer Protocol), FTP (also known as File Transfer Protocol), FTPS (File Transfer Protocol SSL) protocols.

Tüm FTP operation'ları application server'da gerçekleştirilir, bu yüzden client'tan/client'a dosya transferi desteklenmez.All FTP operations are performed on application server,so transferring files from/to client is not supported.

FTP Server'a BağlantıConnection to FTP Server

Tüm file server operation'ları, MAKEFTPCONNECTION komutu kullanılarak kurulan bir file server connection'ı içinde çalıştırılmalıdır. MAKEFTPCONNECTION komutu, file server'a bağlanmak için host, port, username ve password alır. Port parametresi opsiyoneldir ve default port'lar FTP için 21, FTPS için 990, SFTP için 22'dir.All file server operations must be executed inside and file server connection which is established using MAKEFTPCONNECTION command. MAKEFTPCONNECTION command takes host, port, username and password to connect file server. Port parameter is optional and default ports are 21 for FTP, 990 for FTPS, 22 for SFTP.

Ayrıca, programcılar MAKEFTPCONNECTON komutuna connection protocol'ünü sağlamalıdır. Bu seçenek bir symbol değildir ve development aşamasında seçilmelidir. Protocol parametresi opsiyoneldir ve default seçenek FTP'dir.Additionally, programmers must provide the connection protocol to MAKEFTPCONNECTON command. This option is not a symbol and must be selected on development phase. Protocol parameter is optional and default option is FTP.

İşte komutun syntax'ı:Here is the syntax of the command:

MAKEFTPCONNECTION HOST {host} [PORT {port}] [USERNAME {username}]
                              [PASSW {password}][PROTOCOL {FTP|FTPS|SFTP}];

Sistem, farklı file server'lara birden fazla session oluşturmaya izin verir, ama aynı file server'a birden fazla session oluşturmaya gerek yoktur. Farklı server'lar arasındaki ayırt edici parametre, connection'ın HOST parametresidir, bu yüzden sistem aynı host'a birden fazla connection'a izin vermez. Connection yönetiminin scope'u execution context'idir, bu yüzden her transaction veya TROIA component'inin kendi connection pool'u vardır.System allows creating multiple sessions to different file servers, but there is no need to create multiple sessions to same file server. Distinctive parameter between different servers is HOST parameter of connection, so system does not allow multiple connections to same host. Scope of connection management is execution context, so every transaction or TROIA component has its own connection pool.

TROIA programcısı, operation bittikten sonra tüm connection'ları kapatmaktan sorumludur. MAKEFTPCONNECTION tarafından kurulan connection'ı kapatmak için CLOSEFTPCONNECTION komutu kullanılır. İşte syntax:TROIA programmer is responsible close all connections after operation finished. CLOSEFTPCONNECTION command is used to close connection which is established by MAKEFTPCONNECTION. Here is the syntax:

CLOSEFTPCONNECTION {host};

Ayrıca sistem, transaction kapatma operation'ından önce kalan açık connection'ları kapatmaya çalışır, ama tüm ftp operation'ları bittikten sonra ftp connection'larını açık bırakmak önerilmez. İşte bir ftp server'a bağlanan ve connection'ı kapatan örnek bir kod. Lütfen kodu geçerli/geçersiz host ve login credential'larıyla test edin.Additionally system tries to kill remaining open connections before transaction close operation, but it is not recommended to leave ftp connections open after all ftp operations finished. Here is a sample code that connects an ftp server and closes connection. Please test the code with valid/invalid host and login cridentials.

OBJECT:
        STRING FTPHOST,
        STRING FTPPASS,
        STRING FTPUSER;

FTPHOST = 'anyftp.com.tr';
FTPUSER = 'user';
FTPPASS = 'password';

MAKEFTPCONNECTION HOST FTPHOST USERNAME FTPUSER PASSW FTPPASS PROTOCOL FTP;

IF SYS_STATUS == 0 THEN
        /* connection is successful */
ELSE
        /* connection failed */
ENDIF;

CLOSEFTPCONNECTION FTPHOST;

FTP Connection'larında Olası HatalarPossible Errors on FTP Connections

Hem MAKEFTPCONNECTION hem CLOSEFTPCONNECTION komutları, connect/disconnect süreci başarısız olursa SYS_STATUS ve SYS_STATUSERROR'ı ayarlar. Ayrıca tüm exceptional durumlar trace dosyalarına eklenir. İşte bazı olası exception'lar ve çözümler.Both MAKEFTPCONNECTION and CLOSEFTPCONNECTION commands set SYS_STATUS and SYS_STATUSERROR, if connect/disconnect process fails. Also all exceptional cases are inserted to trace files. Here are some possible exceptions and solutions.

Working DirectoryWorking Directory

File server'a connection kurulduktan sonra, client'a bir working directory atanır ve tüm komutlar bu path'te çalıştırılır. Ayrıca, relative dosya path'leri bu working directory'den hesaplanır.After connection established to file server, a working directory is assigned to a client and all commands executed in this path. Also, relative file paths are computed from this working directory.

Şu anda hangi directory üzerinde çalıştığınızı okumak için FTPRUNCOMMAND'ın CURRENTDIRECTORY varyasyonu kullanılır. Working directory'yi değiştirmek FTPRUNCOMMAND'ın CHANGEDIRECTORY varyasyonuyla mümkündür. Bu komut ayrıca FTP server'da bazı başka operation'lara da izin verir, daha fazla bilgi için lütfen komut help'ine bakınız. İşte iki varyasyonun syntax'ı.To read, currently which directory are you working on FTPRUNCOMMAND’s CURRENTDIRECTORY variation is used. Changing working directory is possible with FTPRUNCOMMAND’s CHANGEDIRECTORY variation. This command also allows some other operations on FTP server for more information please see the command help. Here is the syntax of two variations.

FTPRUNCOMMAND CURRENTDIRECTORY TO {targetvariable} ON {host};
FTPRUNCOMMAND CHANGEDIRECTORY {pathonftpserver} ON {host};

Dosya AktarmaTransferring Files

Ftp operation'larının ana işlevleri olarak dosya upload ve download etme, MAKEFTPCONNECTION komutu kullanılarak kurulan bir FTP connection'ında çalıştırılmalıdır. Ayrıca user bilgisi ve permission'lar connection ile ilgilidir. Hem upload hem download komutları, operation'ın gerçekleştirileceği connection'ı gösteren host alır.As main functionalities of ftp operations uploading and downloading files must be executed in a FTP connection which is established by MAKEFTPCONNECTION command. Also user information and permissions is about the connection. Both uploading and dowloading commands gets host which shows ftp connection to perform operation on.

Tüm upload ve download path'leri working directory'den relative olarak hesaplanır. Bu yüzden programcılar dosyaları upload ve download etmeden önce doğru working directory'de olduklarından emin olmalıdır.All upload and download paths are computed relatively from working directory. So programmers must be sure they are in correct working directory before upload and download files.

Dosyanın indirileceği/upload edileceği path, application server'da geçerli bir path olmalıdır. * ile başlayan path'ler (client tarafı path'ler) FTP operation'ları için geçerli değildir. Dosyalar client'ta ise veya client'a indirilmesi gerekiyorsa, programcılar dosyayı ilgili file komutlarını kullanarak server'a transfer etmelidir.Path which file downloaded to/uploaded from must be a valid path on application server. Paths starting with * (client side paths) are not valid for FTP operations. If files are located on client or must be downloaded to client, programmers must transfer file to the server using related file commands.

Dosya İndirmeDownloading Files

Dosya indirmek için FTPDOWNLOAD komutu kullanılır. İşte komutun syntax'ı:To download files FTPDOWNLOAD command is used. Here is the syntax of the command:

FTPDOWNLOAD {pathonftpserver} TO {localpath} FROM {host};

İndirme operation'ı başarısız olursa, sistem SYS_STATUS ve SYS_STATUSERROR system variable'larını ayarlar, ayrıca exception'lar trace'e eklenir. Olası indirme sorunları aşağıdadır:If downlaoding operation fails, system sets SYS_STATUS and SYS_STATUSERROR system variables, also exceptions are inserted to trace. Possible uploading problems are below:

OBJECT:
        STRING FTPHOST,
        STRING FTPPASS,
        STRING FTPUSER,
        STRING LOCALPATH,
        STRING FTPSERVERPATH;

FTPHOST = 'anyftp.com.tr';
FTPUSER = 'user';
FTPPASS = 'password';
FTPSERVERPATH = 'file.xml';
LOCALPATH = 'TempFiles\file.xml';

MAKEFTPCONNECTION HOST FTPHOST USERNAME FTPUSER PASSW FTPPASS PROTOCOL FTP;

IF SYS_STATUS == 0 THEN
        FTPDOWNLOAD FTPSERVERPATH TO LOCALPATH FROM FTPHOST;
ENDIF;

CLOSEFTPCONNECTION FTPHOST;

Dosya Upload EtmeUploading Files

Dosya upload etmek için FTPUPLOAD komutu kullanılır. İşte komutun syntax'ı:To upload files FTPUPLOAD command is used. Here is the synta of the command:

FTPUPLOAD {localpath} TO {host};

Upload operation'ı başarısız olursa, sistem SYS_STATUS ve SYS_STATUSERROR system variable'larını ayarlar, ayrıca exception'lar trace'e eklenir. Olası upload sorunları aşağıdadır:If uploading operation fails, system sets SYS_STATUS and SYS_STATUSERROR system variables, also exceptions are inserted to trace. Possible uploading problems are below:

OBJECT:
        STRING FTPHOST,
        STRING FTPPASS,
        STRING FTPUSER,
        STRING LOCALPATH,
        STRING FTPSERVERPATH;

FTPHOST = 'anyftp.com.tr';
FTPUSER = 'user';
FTPPASS = 'password';
FTPSERVERPATH = 'file.xml';

MAKEFTPCONNECTION HOST FTPHOST USERNAME FTPUSER PASSW FTPPASS PROTOCOL FTP;

IF SYS_STATUS == 0 THEN
        FTPUPLOAD LOCALPATH TO FTPHOST;
ENDIF;

CLOSEFTPCONNECTION FTPHOST;

Dosyaları ListelemeListing Files

FTP Infrastructure dosyaları listelemeyi destekler. Operation, FTPRUNCOMMAND komutunun LISTFILE varyasyonuyla tetiklenir ve working directory olarak çalıştırılır. Bu komutun sonucu, FILELIST komutuna benzer şekilde bir table symbol'üne atanmalıdır. Bu komut ayrıca FTP server'da bazı başka operation'lara da izin verir, daha fazla bilgi için lütfen komut help'ine bakınız. İşte dosyaları listelemek için syntax:FTP Infrastructure supports listing files. Operation is fired by FTPRUNCOMMAND command’s LISTFILE variation and executed as working directory. Result of this command must be assigned to a table symbol, similar to FILELIST command. This command also allows some other operations on FTP server for more information please see the command help. Here is the syntax to list files:

FTPRUNCOMMAND FILELIST TO {targettable} ON {host};

İşte initial directory'deki dosyaları listeleyen ve yazdıran bir örnek.Here is an example that lists and prints file on initial directory.

OBJECT:
        STRING FTPHOST,
        STRING FTPPASS,
        STRING FTPUSER,
        TABLE FILESTABLE,
        STRING STRINGVAR3;

FTPHOST = 'anyftp.com.tr';
FTPUSER = 'user';
FTPPASS = 'password';

MAKEFTPCONNECTION HOST FTPHOST USERNAME FTPUSER PASSW FTPPASS PROTOCOL FTP;

IF SYS_STATUS == 0 THEN

        FTPRUNCOMMAND FILELIST TO FILESTABLE ON FTPHOST;

        LOOP AT FILESTABLE
        BEGIN
                STRINGVAR3 = STRINGVAR3 + FILESTABLE_NAME + TOCHAR(10);
        ENDLOOP;

ENDIF;

CLOSEFTPCONNECTION FTPHOST;

Folder ve Dosya Oluşturma/SilmeCreating/Deleting Folders and Files

Infrastructure, TROIA programcısının working directory'de folder oluşturmasına ve silmesine izin verir. Bu operation'lar, MAKEFTPCONNECTION komutu kullanılarak kurulan bir ftp connection'ında çalıştırılır. Folder oluşturmak, silmek ve dosya silmek için FTPRUNCOMMAND komutunu kullanın. Bu komut ayrıca FTP server'da bazı başka operation'lara da izin verir, daha fazla bilgi için lütfen komut help'ine bakınız. İşte directory ve dosya operation'ları için syntax:Infrastructure allows TROIA programmer to create and delete folders on working directory. These operations are executed on a ftp connection which is established by MAKEFTPCONNECTION command. To create and delete folders and delete files use FTPRUNCOMMAND command. This command also allows some other operations on FTP server for more information please see the command help. Here is the syntax for directory and file operations:

FTPRUNCOMMAND DELETEDIRECTORY {pathonftpserver} ON {host};
FTPRUNCOMMAND DELETEFILE {pathonftpserver} ON {host};
FTPRUNCOMMAND CREATEDIRECTORY {pathonftpserver} ON {host};

İşte ftp server'da bir folder oluşturan, directory değiştiren, local bir dosya upload eden ve son olarak dosyayı ve directory'yi silen bir örnek.Here is an example, that creates a folder on ftp server, changes directory, uploads a local file, finally deletes file and directory.

OBJECT:
        STRING FTPHOST,
        STRING FTPPASS,
        STRING FTPUSER,
        STRING LOCALPATH,
        STRING FTPSERVERPATH,
        STRING DIRNAME,
        TABLE FILESTABLE;

FTPHOST = 'anyftp.com.tr';
FTPUSER = 'user';
FTPPASS = 'password';
DIRNAME = 'myfolder';

LOCALPATH = 'file.xml';

MAKEFTPCONNECTION HOST FTPHOST USERNAME FTPUSER PASSW FTPPASS PROTOCOL FTP;

IF SYS_STATUS == 0 THEN

        FTPRUNCOMMAND CREATEDIRECTORY DIRNAME ON FTPHOST;
        FTPRUNCOMMAND CHANGEDIRECTORY DIRNAME ON FTPHOST;

        FTPUPLOAD LOCALPATH TO FTPHOST;
        FTPRUNCOMMAND DELETEFILE 'file.xml' ON FTPHOST;

        FTPRUNCOMMAND DELETEDIRECTORY DIRNAME ON FTPHOST;

ENDIF;

CLOSEFTPCONNECTION FTPHOST;