Tuesday, July 17, 2007


SAP provide sample code to connect to FTP.

It provided in SAP function module, FTP_CONNECT (connect to FTP), FTP_COMMAND (send command by FTP), FTP_DISCONNECT (disconnect),FTP_R3_TO_SERVER (put file to FTP),FTP_SERVER_TO_R3 (get file from FTP).

Instead of writing a new code, I will try to give you explanation on SAP sample code.

I will explore program RSFTP002.

Program RSFTP002 demonstrate how to send command to FTP.

You can send any FTP command by this program.
For RFC destination use SAPFTP or SAPFTPA. Those are standard RFC destination to connect to FTP. SAPFTP run on client, and SAPFTPA run on application server.

First step of this program is using FTP_CONNECT, don't forget to use scrambled password.
Then we send a command to FTP by using FTP_COMMAND.
To disconnect, use FTP_DISCONNECT.

To copy, or get a file from SAP to/from FTP, you can explore RSFTP002. It demonstrate how to use FTP_R3_TO_SERVER (put file to FTP) & FTP_SERVER_TO_R3 (get file from FTP).
Other way is send put command using FTP_COMMAND. To put a file, do this steps, change FTP directory using "cd dir", change local directory using "lcd localdir", then send put command "put file".


Rose said...

Hello alionzo,

I have done one interface program.In that i am getting one text file data by using FTP connections successfully.

Now my requirement has been changed to get excel file data instead of text file data from the non sap server.
So please help me if any one knows solution.

I have tried in same way as getting text file data.but it is going to dump and some times getting some #$## like this in my internal table.

So pls guide me what is the procedure to get excel file data from other server by using FTP connections only.


alionzo said...

Hi Rose,

FTP is about copying file, opening excel file is another process.
I suggest you to put it into 2 separate process:

First, copy file from remote server into local server.

Second, open excel file using ABAP OLE automation. Just search in google with keyword "ABAP excel".

Hope it help,

Rose said...

Hello alionzo,

Could you please elaborate on ABAP OLE automation. Thanks in advance


alionzo said...

Here is the definition in wikipedia:

In simple words: ABAP did not recognized Excel format, so to make an excel file readable, ABAP must use OLE as an interpreter.

Here is the sample of accessing excel from ABAP:

Rose said...

Hello alionzo,

Thank you. The sites were helpful too.


Rose said...

Hello alionzo,

Is it not possible to schedule the FTP_CONNECT, FTP_R3_TO_SERVER FM in background?


alionzo said...

Yes, it is possible to schedule FTP function module in background.
To make sure, use SAPFTPA instead SAPFTP in RFC destination. Because SAPFTP run on client, and SAPFTPA run on application server.

Anonymous said...

Hi. Do you know the reason why when I ftp file to the server, the contents of the internal table from SAP is in the single line? If for example I have 12 records in the internal table, when I transfer it to the server, all the 12 records are in a single row. I need to show all the records as it is in the internal table. Please help.

Anonymous said...

Any one can help

I have to read vender data from sap into a text file , then I have to send the file to an SQL server .

How can I do that


alionzo said...

to export SAP data to SQL server you can use SAP Automation (RFC).
Here is link if you want to explore more:

or you can open google, find "SAP Visual Basic"

Anonymous said...

Hello Alionzo , Need your suggestion for transfering spool output which is in PDF format to Portal server .

Can we use these FTP functions to transfer SPOOL output(which is stored in R/3 server ) as PDF to another Server . Please help as I have to publish one of my query output which is in spool to portal server .


Ajay Shetty said...

Hi Alionzo,

I am working on this concept of FTP...
As mentioned by You in your post I have followed the same steps...

Actually I have internal table it_final with some data (Report)
I have to place this in a directory called INBOUND

I used SAPFTP as destination
FM used by me are..
http_scrumble to scrumble pwd
ftp_connect to connect to ftp
ftp_command to open folder INBOUND using cd inbound
ftp_r3_to_server passing the same file name used in ftp_connect using put filename and
table as internal table..it_final
file is being created in INBOUND dir..
but data transfered is showing as 0 bytes...

Please help....

shriram said...

nice blog

Anonymous said...

Hi, I have to send a file from SAP to another server in background mode. I am using RFC destination as 'SAPFTPA'. when i execute the program in background, I could see the file is being created but with '0' bytes. When i run the program in debug mode I could successfully place the file in the ftp server. Pls let me know what are the additional steps need to be done for background processing.


Suman said...

Hi alionzo
i have a similar requirement.
i need to upload any (doc/pdf/bmp/jpeg/xls/txt) files to FTP from portal.

i'll be getting a raw string from portal which i'll internally convert to binary & store in FTP.
it's working fine for txt file.
but for other files, file is getting created in FTP but data is incorrect.

FM's used:

can u pls suggest


seventyros said...

For a Excellent Online Resource for SAP EP and SAP Web Dynpro ABAP, Visit Learn SAP Online

This comment has been removed by the author.

I got gd in connecting to FTP for both sending and retrieving data by mentioning user-id,password and ip address. If at all I have to pass a specific Port no along with ip address...How to do that ?? [ As my client has restricted all ports and opened only few ports like 8080,.. Please help me

Anonymous said...

and why not with:
is this not the same?

itsme said...

Hi..can i send my text file to ftp server to their partition for example i wan to send text file to d:/outbox folder in ftp server?
Pls help me..

itsme said...

Can i send text file to folder in ftp server?
For example i want to send my text file to folder d:/outbox in ftp server..
Pls help me

yektek training said...

nice post thank you

siva sankar Sankar said...

excellent post thanks for sharing from Sankar

Network Solutions Reviews said...

Thanks for sharing such a good information...

getmcdonaldscouponsfree said...

Thanks for taking your time writing this post! Cheers, coupon and voucher
Also, feel free to visit my blog http://getmcdonaldscouponsfree.wordpress.com/