cancel
Showing results for 
Search instead for 
Did you mean: 

get/put dynamic file name using FTP

Former Member
0 Kudos

Hi Friends,

I am currently using FTP_Connect, FTP_command and FTP_disconnect to get/put a file from a remote server.

But the file name was changed to add a date/time stamp.

So the filename became dynamic (example from 'test.txt' to 'test_200512160800.txt').

I tried using get test. but my FTP command failed. Do you know anyway of doing this?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi LeGo,

you may create a script (using ABAP-command TRANSFER)

for FTP like this

<b># FTP Script

ftp -n -v <<EOF

open 125.123.83.70

user .FTPUSER password

ascii

get /...remotefile /usr/...localfile

quit

EOF</b>

and then excecute the script with

<b>SXPG_COMMAND_EXECUTE</b> (see docu)

first define an extern command with SM69

Viktor

Answers (2)

Answers (2)

andreas_mann3
Active Contributor
0 Kudos

Hi ,

use fm EPS_GET_DIRECTORY_LISTING

sample:

  concatenate 'test_'  sy-datum '*.txt' into mask.

  CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
       destination dest
       EXPORTING
            DIR_NAME               = verz
            FILE_MASK              = mask
       IMPORTING
            FILE_COUNTER           = cnt_file
            ERROR_COUNTER          = err_file
       TABLES
            DIR_LIST               = dir_list
       EXCEPTIONS
            INVALID_EPS_SUBDIR     = 1
            SAPGPARAM_FAILED       = 2
            BUILD_DIRECTORY_FAILED = 3
            NO_AUTHORIZATION       = 4
            READ_DIRECTORY_FAILED  = 5
            TOO_MANY_READ_ERRORS   = 6
            EMPTY_DIRECTORY_LIST   = 7
            OTHERS                 = 8.

Andreas

Former Member
0 Kudos

Hello Andreas,

Can you please give me a sample code on how to use this function module EPS_GET_DIRECTORY_LISTING.

andreas_mann3
Active Contributor
0 Kudos

Hi Lego,

here's another sample for the fm:

REPORT ztest_epsf.

PARAMETERS: date LIKE sy-datum,
            dir  TYPE epsf-epsdirnam,
            pattern TYPE epsf-epsfilnam,
            zid   LIKE vers_dest-rfcdest.

DATA dir_list LIKE epsfili OCCURS 0 WITH HEADER LINE.
DATA cnt_file TYPE epsf-epsfilsiz.
DATA err_file TYPE epsf-epsfilsiz.


START-OF-SELECTION.
  IF date IS INITIAL.
    date = sy-datum.
  ENDIF.

*build pattern with input-pattern and date
  CONCATENATE pattern date '*' INTO pattern.



*search for files in foreign system
  CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
       DESTINATION                   zid
       EXPORTING
            dir_name               = dir
            file_mask              = pattern
       IMPORTING
            file_counter           = cnt_file
            error_counter          = err_file
       TABLES
            dir_list               = dir_list
       EXCEPTIONS
            invalid_eps_subdir     = 1
            sapgparam_failed       = 2
            build_directory_failed = 3
            no_authorization       = 4
            read_directory_failed  = 5
            too_many_read_errors   = 6
            empty_directory_list   = 7
            OTHERS                 = 8.

  WRITE: / pattern.
  ULINE.

  LOOP AT dir_list.
    WRITE: / dir_list-name.
  ENDLOOP.

  ULINE.
  WRITE: / cnt_file.
  WRITE: / err_file.

pls reward points for useful hints.

thanks and

regards Andreas

Former Member
0 Kudos

Hello Andreas,

I tried using SAPFTP/SAPFTPA as my RFC destination but I always get a return code of 8 from the function module.

Should I setup the external system as my RFC destination?

Former Member
0 Kudos

Hi Lego,

IF WE PROVIDE THE WRONG DESTINATION

THEN SY-SUBRC WILL BE 8

(I JUST TRIED AND SAW)

1. see tcode sm59

(ur basis team might help u)

2. under the node

R/3 connections,

various connections are setup

to use.

3. U can use one of them (in your DESTINATION 'XYZ')

if it serves ur purpose.

regards,

amit m.

Message was edited by: Amit Mittal

Former Member
0 Kudos

Hello friends. I now know the solution, I figured out just now. Just use 'mget' or 'mput'. Just want to share to those who don't know this yet.

Former Member
0 Kudos

Another solution is write a small shell scrip/batch program to convert all the abc.12345 to single abc.txt.. then call ur file frm the server.

Regards

Rahul

Former Member
0 Kudos

Sorry guys. I thought it was working. I overlooked that the same file was already sitting in the UNIX directory so the upload program was able to read it. I assume that 'mget' or 'mput' don't work using the FTP_command function module.

Any ideas aside from the using a unix shell script?

former_member188685
Active Contributor
0 Kudos

Hi Lego,

Try to Provide RFC destination to that Function module.

so that you can check that ..

Provide the COrrect RFC destination...

regards

vijay