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

Creating A File Using FTP Commands

Former Member
0 Likes
1,149

Hello! Could someone please help me with this one?

The requirement calls for a simple text file to be created in a different server. What is currently used is the WS_DOWNLOAD function, but it is not working properly, probably due to two things: the target folder path and filename is too long, or that the program is to be run in the background. The result is that the file is being saved in a different path.

I am looking into using FTP functions (FTP_CONNECT, FTP_COMMAND, FTP_DISCONNECT), but I have no prior experience in using this.

Probably my question is how to use the FTP_COMMAND, and which command to use in order to create the file? It should mimic the WS_DOWNLOAD function.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
730

here is the code for downloading to any palce in the server.

PARAMETERS: p_file like rlgrap-filename.

* Internal table to store export data   
  DATA: begin of it_excelfile occurs 0,
   row(500) type c,
   end of it_excelfile.
   CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*          BIN_FILESIZE            =
           filename                = p_file         "File name
           filetype                = 'ASC'          "File type
*     IMPORTING
*          FILELENGTH              =
      TABLES
           data_tab                = it_excelfile   "Data table
      EXCEPTIONS
           file_write_error        = 1
           no_batch                = 2
           gui_refuse_filetransfer = 3
           invalid_type            = 4
           OTHERS                  = 5.
    IF sy-subrc <> 0.
      MESSAGE i003(zp) WITH
               'There was an error during Excel file creation'(200).
      exit. "Causes short dump if removed and excel document was open  
    ENDIF.
  ENDIF.

reward points if it is usefull ...

Girish

4 REPLIES 4
Read only

Former Member
0 Likes
730

Hi,

for sending the data to the target system i am using FTP_COMMAND by passing the 'put' statement along with the soruce and destinations for the command parameter.

See the bellow code

CONCATENATE 'put' v_fname '
' 'wbrs1\' folder

into cmd separated by space.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

HANDLE = dhdl

command = cmd

COMPRESS = 'N'

  • VERIFY =

  • RFC_DESTINATION =

  • IMPORTING

  • FILESIZE =

  • FILEDATE =

  • FILETIME =

tables

data = result

EXCEPTIONS

TCPIP_ERROR = 1

COMMAND_ERROR = 2

DATA_ERROR = 3

OTHERS = 4

.

Here v_name is the file path and name in the application server suppose say :

/usr/sap/TD2/DVEBMGS01/work/TD2_20060901_1008_WAY-LY.XLS

and wbrs1 is the target system and 'Waynesboro DFS' is the folder name i ma passing to the command .

Also tried with the following statement

CONCATENATE 'put' v_fname '
' dhost folder

into cmd separated by space.

concatenate '
wbrs1\' folder into cmd.

concatenate 'put' v_fname cmd into cmd separated by space

<b>Reward points</b>

Regards

Read only

0 Likes
730

I just want to clarify something with the code you sent: is the <b>result</b> table in your code the internal table containing the text file's contents?

Read only

Former Member
0 Likes
731

here is the code for downloading to any palce in the server.

PARAMETERS: p_file like rlgrap-filename.

* Internal table to store export data   
  DATA: begin of it_excelfile occurs 0,
   row(500) type c,
   end of it_excelfile.
   CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*          BIN_FILESIZE            =
           filename                = p_file         "File name
           filetype                = 'ASC'          "File type
*     IMPORTING
*          FILELENGTH              =
      TABLES
           data_tab                = it_excelfile   "Data table
      EXCEPTIONS
           file_write_error        = 1
           no_batch                = 2
           gui_refuse_filetransfer = 3
           invalid_type            = 4
           OTHERS                  = 5.
    IF sy-subrc <> 0.
      MESSAGE i003(zp) WITH
               'There was an error during Excel file creation'(200).
      exit. "Causes short dump if removed and excel document was open  
    ENDIF.
  ENDIF.

reward points if it is usefull ...

Girish

Read only

Former Member
0 Likes
730

You can use following code also to move the files from one directory to another in an application Server.

CONCATENATE mv <file_path> <dir> INTO <local_var> SEPARATED BY space.

CALL 'SYSTEM' ID 'COMMAND' FIELD <local_var>.

Best Regards,

Devesh Singh