Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

FTP upload

Former Member
0 Kudos

Hello experts,

I have one requirement. Now i am downloading sap data in to some file . That file they want in ftp location.

I tried using below function modules

ftp_connect

ftp_command

FTP_DISCONNECT

but i am facing some probelm

tell me the any other logic .

before we need setup anything in our system.

we have to create any rfc destination .

please help me how to face this problem.

7 REPLIES 7

Former Member
0 Kudos

Have a look at this program : RSFTP002

former_member181966
Active Contributor
0 Kudos

HI

Basically its calling up two Fm

call function 'FTP_CONNECT'

call function 'FTP_COMMAND

For FTP command you need to create external command in SM69 and can test it in SM49 .

Then you can use the program RSFTP002.

Hope this’ll give you some idea!! Don’t forget to award points

Good luck !

0 Kudos

Hi ,

which commands i have to create in sm60 transaction .

and how to create that in that trasnation lot of parameters are there.

Please explain clearly

Thanks

janardhan

vinod_gunaware2
Active Contributor
0 Kudos

Look at SM69, SM49 and

Function SXPG_COMMAND_EXECUTE

e.g. SM69

Press F5 or click Change button

Press F6 or click Create

Fill in the following parameter :-

Command name - the unix scripts file name e.g. ZABAPFTP

Operating system command - e.g. sh

Parameters for operating system command - e.g. /sap_production/usr/sap/trans/data/zabapftp.sh

REPORT ZABAPFTP.

data : t_btcxpm like btcxpm occurs 0,

p_addparam like sxpgcolist-parameters,

rep_date like sy-datum,

t_date like SXPGCOLIST-PARAMETERS.

rep_date = sy-datum - 1.

t_date = rep_date.

*p_addparam = '/sap_production/usr/sap/trans/data/zabapftp.sh'.

refresh t_btcxpm. clear t_btcxpm.

call function 'SXPG_CALL_SYSTEM'

EXPORTING

commandname = 'ZABAPFTP'

additional_parameters = t_date

TABLES

exec_protocol = t_btcxpm

EXCEPTIONS

no_permission = 1

command_not_found = 2

parameters_too_long = 3

security_risk = 4

wrong_check_call_interface = 5

program_start_error = 6

program_termination_error = 7

x_error = 8

parameter_expected = 9

too_many_parameters = 10

illegal_command = 11

others = 12.

if sy-subrc ne 0.

write:/ 'Error in ZABAPFTP ', sy-subrc.

endif.

or

You can execute an operating system command in the OPEN DATASET statement using the FILTER addition:

The following example works under UNIX:

DATA DSN(20) VALUE '/usr/test.Z'.

OPEN DATASET DSN FOR OUTPUT FILTER 'compress'.

OPEN DATASET DSN FOR INPUT FILTER 'uncompress'.

The first OPEN statement opens the file '/usr/test.Z' so that the displayed data can be read into it in compressed form.

The second OPEN statement opens the file '/usr/test.Z' so that the data is decompressed when it is read from the file.

regards

vinod

vinod_gunaware2
Active Contributor
0 Kudos

FTP data from SAP

These are standared FTP programs which allows you to FTP from within SAP.

The SAPFTP.EXE should be pre-installed in the users local harddisk before you can used this functions.

Do a check first by executing program RSFTP005. It will tell you whether it can detect the SAPFTP.EXE program.

RSFTP001 - SAPFTP version

RSFTP002 - Execute FTP Command

RSFTP003 - Test

RSFTP004 - FTP copy

RSFTP005 - SAPFTP check

RSFTP006 - FTP command list

RSFTP007 - Test FB:FTP_SERVER_TO_R3 / FTP_R3_TO_SERVER

RSFTP008 - Test FB:FTP_CLIENT_TO_R3 / FTP_R3_TO_CLIENT

Programming the FTP

Not only does the RSFTP002 program give us a test environment, but it also provides us with a programming example. We can see that the FTP functionality is really provided by a set of function modules all within the SFTP Function Group. We have the basic commands such as FTP_CONNECT, FTP_COMMAND, and FTP_DISCONNECT that can be strung together to create a complete file operation action. The FTP_COMMAND Function allows you to issue arbitrary FTP commands as long as the SAPFTP function, the Host, and the Destination server all support the command. Then you have the specialized functions such as FTP_R3_TO_SERVER, FTP_R3_TO_CLIENT, and FTP_CLIENT_TO_R3. This lets you take some data in memory and transfer it someplace else. This has the advantage of not having to write the data to the file system first and not to have to issue any FTP commands. However these functions are also limited to the scope described.

If you are already familiar with FTP in general, working with these function modules should not seem to difficult. The Connect, Command, Disconnect actions would seem somewhat self explanatory. So instead of looking at the entire program in detail let's focus on two things that may be unfamiliar. First the program starts off with an ABAP Kernel System call to AB_RFC_X_SCRAMBLE_STRING. Well we don't want to pass a potentially sensitive password openly. Therefore the FTP_CONNECT function module requires that the password be encrypted before it receives it. It is this System call that performs that one-way encryption. Now I checked a 620 SP42 system and in this example, SAP has replace the AB_RFC_X_SCRAMBLE_STRING with a function call to HTTP_SCRAMBLE. Unfortunately HTTP_SCRAMBLE doesn't even exist in my 46C system. The only other thing that I wanted to point out about these function calls is the exporting parameter on the FTP_CONNECT. It passes back a parameter called handle. This handle then becomes an importing parameter to all subsequent calls: FTP_COMMAND and FTP_CLOSE. This handle is the pointer to the instance of FTP that we started with the FTP_CONNECT. This assures that we get reconnected to the same FTP session with each command we issue.

FTP Development

DATA: BEGIN OF MTAB_DATA OCCURS 0,

LINE(132) TYPE C,

END OF MTAB_DATA.

DATA: MC_PASSWORD(20) TYPE C,

MI_KEY TYPE I VALUE 26101957,

MI_PWD_LEN TYPE I,

MI_HANDLE TYPE I.

START-OF-SELECTION.

MC_PASSWORD = 'password'.

DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN.

*-- FTP_CONNECT requires an encrypted password to work

CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD MC_PASSWORD ID 'KEY' FIELD MI_KEY

ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD MC_PASSWORD

ID 'DSTLEN' FIELD MI_PWD_LEN.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

USER = 'userid'

PASSWORD = MC_PASSWORD

HOST = 'servername'

RFC_DESTINATION = 'SAPFTP'

IMPORTING

HANDLE = MI_HANDLE

EXCEPTIONS

NOT_CONNECTED = 1

OTHERS = 2.

CHECK SY-SUBRC = 0.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

HANDLE = MI_HANDLE

COMMAND = 'dir'

TABLES

DATA = MTAB_DATA

EXCEPTIONS

TCPIP_ERROR = 1

COMMAND_ERROR = 2

DATA_ERROR = 3

OTHERS = 4.

IF SY-SUBRC = 0.

LOOP AT MTAB_DATA.

WRITE: / MTAB_DATA.

ENDLOOP.

ELSE.

  • do some error checking.

ENDIF.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

HANDLE = MI_HANDLE

EXCEPTIONS

OTHERS = 1.

regards

vinod

0 Kudos

for this code how to create a RFC destination?... i have one requirement like file upload for my network place.can u say this code is work for that requirement?

Former Member
0 Kudos

Hi janardhan,

Earlier i worked on requirement , but it didn't create anything. By default one destination will create in SM59 with FTP.

My suggestion is first try to connect to FTP using the program RSFTP002.

If it is getting connect to FTP you no need to do anything. just place the file using FTP_R3_TO_SERVER.

Regards,

Sri