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_COMMAND: creating sub folders

Former Member
0 Likes
1,706

Hi groups

Iam using FTP_Connect, FTP_command , FTP_R3_TO_SERVER and FTP_disconnect to transfer dat file to FTP server.

  • to create sub folder in ftp server

CONCATENATE 'mkdir'

p_filpth

INTO l_dir

SEPARATED BY space.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = g_handle

command = l_dir

TABLES

data = i_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3.

using FTP_COMMAND can we creater 2 or more subfolders at a time?

Ex: In p_filpth let the file path be like this 1/2/3. 1 and 2 subfolders already exist.now by using the above code iam able to create folder '3'.

but if the filepath is 1/2/3/4. then iam not able to create subfolders 3 and 4. At a time only one sub folder is created.

please suggest me how to create 2 or more subfolders at a time? it's urgent

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,016

Hi,

I have worked lthis type of situtaion...and i coded like this

CLEAR: l_cmd,l_date.

REFRESH l_result.

l_date = sy-datum.

SHIFT l_date LEFT BY 2 PLACES.

CONCATENATE: 'ls pub/inbox/*'(001)

l_date

'struct.txt'(002) INTO l_cmd.

----


connect to ftp server -

PERFORM connect_ftp.

        • DERIVE ALL THE FILES IN '/PUB/INBOX' FOLDER.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = l_hdl

command = l_cmd

TABLES

data = l_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

DELETE: l_result INDEX 1,

l_result INDEX 1,

l_result INDEX 1.

DESCRIBE TABLE l_result.

DELETE l_result INDEX sy-tfill.

Thanks,

Pramod

6 REPLIES 6
Read only

Former Member
0 Likes
1,016

<b>

see the below code it was working for creating subfolder with in a folder ...</b>

REPORT ZFTPSAP 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.

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

reward points if it is usefull ....

Girish

Read only

Former Member
0 Likes
1,017

Hi,

I have worked lthis type of situtaion...and i coded like this

CLEAR: l_cmd,l_date.

REFRESH l_result.

l_date = sy-datum.

SHIFT l_date LEFT BY 2 PLACES.

CONCATENATE: 'ls pub/inbox/*'(001)

l_date

'struct.txt'(002) INTO l_cmd.

----


connect to ftp server -

PERFORM connect_ftp.

        • DERIVE ALL THE FILES IN '/PUB/INBOX' FOLDER.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = l_hdl

command = l_cmd

TABLES

data = l_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

DELETE: l_result INDEX 1,

l_result INDEX 1,

l_result INDEX 1.

DESCRIBE TABLE l_result.

DELETE l_result INDEX sy-tfill.

Thanks,

Pramod

Read only

0 Likes
1,016

thank u for the response

let p_filpath be '/new/efmp/filo/fi/'

Already folders new, efmp are present in the server.

Now iam trying to created two new folder 'filo' and 'fi' at a time.

CONCATENATE 'ls'

p_filpth

INTO l_dir

SEPARATED BY space.

CONCATENATE l_dir 'struct' into l_dir.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = g_handle

command = l_dir

TABLES

data = i_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3.

if sy-subrc eq 0.

***l_fname = '/new/efmp/filo/fi/test.csv'

CALL FUNCTION 'FTP_R3_TO_SERVER'

EXPORTING

handle = g_handle

fname = l_fname

  • BLOB_LENGTH =

character_mode = c_x

TABLES

  • BLOB =

text = p_i_final_csv

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4

.

endif.

after using ftp_command, filepath('/new/efmp/filo/fi/) is being created (i.e 2 new folders 'filo' and 'fi' are created but CALL FUNCTION 'FTP_R3_TO_SERVER' is failing.

Read only

0 Likes
1,016

u can not create subfolder inside subfolder at a time even in unix and dos..

us have to use :

mkdir filo

cd filo

mkdir fi

each time u have to use <b>FTP_COMMAND</b>

Then do other operations...

reward if useful..

Read only

0 Likes
1,016

i tired what u have told and it worked. at a time only one subfolder can be created

Read only

0 Likes
1,016

To create more than one sub folder at a time.. u need to write a script on application server... which is not an easy way...

so I think u can use.. this method only.