Application Development and Automation 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: 
Read only

FTP_CONNECT parameters

Former Member
0 Likes
2,920

Hi,

I wanto to connect to an FTP server & change the files in a folder. For that I am using FTP_CONNECT.

I have gone thru the web blog & discussion on forum but not getting what I have to pass as host. Also what is meant by user & password that I have to pass.

Enen in standard programs RSFTP002,RSFTP003,RSFTP004 parameters are taken as char.

Please clear my doubts.

Regards,

Dilip

Message was edited by: Diliip Gupchup

Message was edited by: Diliip Gupchup

Hi,

I wanto to connect to an FTP server & change the files in a folder. For that I am using FTP_CONNECT.

I have gone thru the web blog & discussion on forum but not getting what I have to pass as host. Also what is meant by user & password that I have to pass.

Enen in standard programs RSFTP002,RSFTP003,RSFTP004 parameters are taken as char.

Please clear my doubts.

Regards,

Dilip

Message was edited by: Diliip Gupchup

Message was edited by: Diliip Gupchup

5 REPLIES 5
Read only

Former Member
0 Likes
1,477
data: p_host(64) TYPE c.

p_host = sy-host.
p_user and p_pwd are ftp user id and password


CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
      user            = p_user
      password        = p_pwd
      host            = p_host
      rfc_destination = c_dest
    IMPORTING
      handle          = l_hdl
    EXCEPTIONS
      OTHERS          = 1.
Read only

0 Likes
1,477

Hi Chandrasekhar,

My FTP folder is on some machine so here sy-host will not work.

Example for my FTP folder is as below:

<b> FTP://nameNAME/folder</b>

I want to access this <i>folder</i>

Regards,

Dilip

Read only

0 Likes
1,477

Hi Dilip,

You need use FTP_COMMAND after FTP_CONNECT.

PSEUDOCODE.
 CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
      USER                   = V_USER
      PASSWORD               = V_PWD
*       ACCOUNT                =
      HOST                   = HOST
      RFC_DESTINATION        = V_DEST
*       GATEWAY_USER           =
*       GATEWAY_PASSWORD       =
*       GATEWAY_HOST           =
    IMPORTING
      HANDLE                 = HDL
    EXCEPTIONS
      NOT_CONNECTED          = 1
      OTHERS                 = 2.

  IF SY-SUBRC <> 0.
    CLEAR V_PWD.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    STOP.
  ENDIF.


  CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
      HANDLE              = HDL
    COMMAND             = 'lcd c:'
*       COMPRESS            =
*       VERIFY              =
*     IMPORTING
*       FILESIZE            =
*       FILEDATE            =
*       FILETIME            =
    TABLES
      DATA                = IT_RESULT
   EXCEPTIONS
     TCPIP_ERROR         = 1
     COMMAND_ERROR       = 2
     DATA_ERROR          = 3
     OTHERS              = 4

Regards,

Raghav

Read only

Former Member
0 Likes
1,477

have u checked this report , DOCVLTCH01

Read only

Former Member
0 Likes
1,477

Check this report might help u.

The User and ID are used for the authentication of the call. This is set to validate ID and password in any normal system.

REPORT zbau0010_test.

TABLES: usr01.

DATA : BEGIN OF mtab_data OCCURS 0,

line(132),

END OF mtab_data.

DATA: BEGIN OF it_file OCCURS 0,

line(250),

END OF it_file.

DATA : mi_key TYPE i VALUE 26101957,

mi_pwd_len TYPE i,

mi_handle TYPE i, mc_command(250).

PARAMETERS : p_sfile(255),

p_tfile(255),

p_host(20) TYPE c OBLIGATORY,

p_login(20) TYPE c LOWER CASE,

p_psswd(20) TYPE c LOWER CASE,

p_nftp(1) TYPE p DEFAULT 5.

SELECT-OPTIONS: s_receiv FOR usr01-bname.

START-OF-SELECTION.

DO p_nftp TIMES.

  • Connect

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = ' '

password = ' '

host = p_host

rfc_destination = 'SAPFTPA'

IMPORTING

handle = mi_handle

EXCEPTIONS

not_connected = 1

OTHERS = 2.

IF sy-subrc EQ 0.

p_sfile = '\urc_sap_file\inbound\files\'.

CONCATENATE 'ls' p_sfile INTO mc_command SEPARATED BY

space.

  • Put file

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = mi_handle

command = mc_command

TABLES

data = mtab_data

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc = 0.

DELETE mtab_data FROM 1 TO 3.

LOOP AT mtab_data.

MOVE mtab_data-line+39 TO it_file-line.

APPEND it_file.

CLEAR it_file.

WRITE : / mtab_data.

ENDLOOP.

ENDIF.

DATA: ftpcommand(256).

ftpcommand = 'dir'.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = mi_handle

command = ftpcommand

TABLES

data = it_file

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc = 0.

LOOP AT it_file.

WRITE: / it_file.

ENDLOOP.

ENDIF.

  • Disconnect

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = mi_handle

EXCEPTIONS

OTHERS = 1.

ENDIF.

ENDDO.