Skip to Content

Connection FTP Report

Hello Experts,

How can I establish an FTP connection from an ABAP report? and once established can I import the data into the internal table?

please provide me with a simple example code.

Thank you

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jul 10, 2020 at 08:44 AM

    Since I last checked, SAP only supports FTP connections by default. It does not support SFTP (SSH File Transfer Protocoll). SFTP connections require a custom project including your basis team.

    This is what you need to do to connect and interact with a server through FTP. For further information, look on github to find example codings https://github.com/search?q=abap+ftp.

    1. Your inputs that you need are:

    • FTP Username
    • FTP Password
    • Flag whether Password is already scrambled
    • FTP Server-/Hostname
    • TCPIP RFC-Destination for internal program 'sapftp', by default this is 'SAPFTPA'

    2. Scramble Password

    In case your password is still plain text, you need to scramble it with FM 'HTTP_SCRAMBLE' using the plain text password, its length and the key '26101957'.

    3. Connect to the FTP Host

    To connect to the FTP host, you need to call FM 'FTP_CONNECT' with user, scrambled password, hostname and RFC Destination for the sapftp program (e.g. SAPFTPA). The returned handle lets you reuse the ftp session until you close it, or until it is closed automatically after e.g. a timeout.

    4. Interact with the FTP Host on directory level

    To interact (read/write) with the FTP Host, you need to call FM 'FTP_COMMAND' with the handle of your FTP session and the ftp command. (alternatively, you can also send a list of commands at once with FM 'FTP_COMMAND_LIST')

    • Change directory: cd yourdirectory
      Go up a directory: cd ..
      Go to root directory: cd "/"
    • Get current directory list (folders and files): ls -la (or also just 'dir')
    • Renaming a file or directory: rename currentname newname
    • Switch character mode for transferring text files: ascii

    5. Upload / Download files from FTP host

    To download a file from the FTP server, you use FM 'FTP_SERVER_TO_R3' using the session handle, the file name of the current directory which you either know or get from the directory list, and the character mode 'C' to retrieve the data as TEXT (internal text table).

    To upload a file to the FTP server, you use FM 'FTP_R3_TO_SERVER' using the session handle, the file name for the current directory. If you want to send it as 'BLOB' (binary data), you will have to for example transform a Text String into a X-String with e.g. 'SCMS_STRING_TO_XSTRING' and then transform the X-String into a Binary Tab with e.g. 'SCMS_XSTRING_TO_BINARY'. The resulting binary_tab and output_length need to be passed to the above mentioned FM 'FTP_R3_TO_SERVER' as well.

    6. Disconnect from FTP Host and RFC-Destination

    To disconnect completely, you need to call the FM 'FTP_DISCONNECT' with your FTP session handle and also the FM 'RFC_CONNECTION_CLOSE' for the RFC-Destination (e.g. SAPFTPA)

    Please implement your solution and come back with more specific issues, in case you still have troubles.

    Add a comment
    10|10000 characters needed characters exceeded

    • Francesco Allocca, if with 'download the data', you are referring to downloading the content of a file as TEXT, then after connecting with an FTP server through FM FTP_CONNECT, you will only need FM FTP_COMMAND to switch to the folder, if necessary. Otherwise you use FM FTP_SERVER_TO_R3 to download the content of the file either as TEXT table or as BLOB (binary) table. Prior to downloading the file as TEXT, you might have to set the character mode with FM FTP_COMMAND and sending the ftp command 'ascii'. Not sure right now if you can give relative file locations in FTP_SERVER_TO_R3 (eg ./dir/subdir/file.dat), I have not tried that out. Normally I switch to the correct folder with FTP_COMMAND and then download or upload the file for the current folder.

  • Posted on Jul 08, 2020 at 03:28 PM

    Hi,

    To establish connection to FTP following steps to be followed have listed the function modules to be called and pass parameters accordingly.

    CALL FUNCTION 'HTTP_SCRAMBLE' "For Encrypting the Password

    CALL FUNCTION 'FTP_CONNECT' "For connecting to the FTP Server's user directory

    CONCATENATE logic of file name convention INTO file. " used to select the file to be read.

    Load to the file to Internal table

    CALL FUNCTION 'FTP_DISCONNECT' "For Disconnecting the connected FTP Session

    CALL FUNCTION 'RFC_CONNECTION_CLOSE'

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.