Skip to Content
author's profile photo Former Member
Former Member

SFTP Scripts for file transfer

Hi,

I Have a requirement where in I have to transfer file from SAP system to third party system. I will have to use SFTP process for the same.

Has anybody worked on this before. Did someone created any unix script for SFTP process to transfer file from SAP to third party system.

I know that I will have to create a unix command in SM69 and use FM 'SXPG_Command_Execute'.

Has anybody created a unix script for SFTP? Pls reply back if someone knows it!

Sushil

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 05, 2007 at 12:36 PM

    &----


    *& Report ZFTPCONNECT

    *&

    &----


    &----


    *& Report ZFTPCONNECT

    *&

    • AUTHOR........ Aveek Ghose

    • DATE WRITTEN.. 15/09/2006

    • R/3 RELEASE... 4.6C

    • =====================================================================*

    REPORT ZFTPCONNECT LINE-SIZE 132.

    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.

    *-- Your SAP-UNIX FTP password (case sensitive)

    MC_PASSWORD = 'password'.

    DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN IN BYTE MODE.

    *-- 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

    *-- Your SAP-UNIX FTP user name (case sensitive)

    USER = 'userid'

    PASSWORD = MC_PASSWORD

    *-- Your SAP-UNIX server host name (case sensitive)

    HOST = 'unix-host'

    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.

    WRITE: / 'Error in FTP Command'.

    ENDIF.

    CALL FUNCTION 'FTP_DISCONNECT'

    EXPORTING

    HANDLE = MI_HANDLE

    EXCEPTIONS

    OTHERS = 1.

    ******************************************************************************************

    &----


    *& Report ZUNIXPROG04

    *&

    &----


    *&

    *&

    &----


    REPORT ZUNIXPROG04.

    CONSTANTS lc_movefile TYPE sxpgcolist-name VALUE 'Z_MV'.

    DATA: BEGIN OF lt_result OCCURS 0 .

    INCLUDE STRUCTURE btcxpm .

    DATA: END OF lt_result.

    DATA: lv_params TYPE SXPGCOLIST-PARAMETERS,

    lv_exitcode TYPE btcxpgexit.

    PARAMETERS: p_src TYPE RLGRAP-FILENAME OBLIGATORY,

    p_tgt TYPE RLGRAP-FILENAME OBLIGATORY.

    *PARAMETERS: p_src LIKE FILENAME-FILEEXTERN

    • p_tgt type FILENAME-FILEEXTERN

    CONCATENATE p_src p_tgt

    INTO lv_params

    SEPARATED BY space.

    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'

    EXPORTING

    commandname = lc_movefile

    additional_parameters = lv_params

    IMPORTING

    exitcode = lv_exitcode

    TABLES

    exec_protocol = lt_result

    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

    wrong_asynchronous_parameters = 12

    cant_enq_tbtco_entry = 13

    jobcount_generation_error = 14

    OTHERS = 15.

    IF sy-subrc <> 0.

    MESSAGE e001(zdev).

    ENDIF.

    cheers

    Aveek

    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.