Code: Alles auswählen.
FUNCTION Z_ftp_upload.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(SRC_FILE)
*" REFERENCE(DEST_FILE)
*" REFERENCE(FTP_SERVER)
*" REFERENCE(FTP_USER)
*" REFERENCE(FTP_PASSWD)
*" REFERENCE(FLAG_BINARY) OPTIONAL
*" EXPORTING
*" REFERENCE(SUCCESS_226)
*" TABLES
*" OUTPUT
*" EXCEPTIONS
*" COULD_NOT_OPEN_COMMANDFILE
*"----------------------------------------------------------------------
*-----------------------------------------------------------------------
* DATENDEFINITION
*-----------------------------------------------------------------------
DATA: uuid LIKE sysuuid-c.
DATA: dsn TYPE string.
DATA: fl TYPE string.
DATA: os_command(500).
DATA: BEGIN OF syscalltab OCCURS 0,
line(200),
END OF syscalltab.
*Temporärer Dateiname ermitteln.
" 1. UUID erstellen
CALL FUNCTION 'SYSTEM_UUID_C_CREATE'
IMPORTING
uuid = uuid.
CONCATENATE '/tmp/ftp_' uuid INTO dsn.
* FTP Kommandofile schreiben
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0. RAISE could_not_open_commandfile. ENDIF.
CONCATENATE 'user' ftp_user ftp_passwd
INTO fl SEPARATED BY space.
TRANSFER fl TO dsn.
IF flag_binary NE space.
TRANSFER 'binary' TO dsn.
ENDIF.
CONCATENATE 'put' src_file dest_file INTO fl SEPARATED BY space.
TRANSFER fl TO dsn.
TRANSFER 'bye' TO dsn.
CLOSE DATASET dsn.
* Betriebssystemkommando erstellen.
CONCATENATE 'ftp -n -v' ftp_server '<' dsn
INTO os_command SEPARATED BY space.
CALL 'SYSTEM'
ID 'COMMAND'
FIELD os_command
ID 'TAB'
FIELD syscalltab-*sys*.
MOVE syscalltab[] TO output[].
* temporäres File wieder löschen.
DELETE DATASET dsn.
* FTP Rückmeldungen auswerten
* 226 bedeutet File erfolgreich übertragen
LOOP AT syscalltab.
IF syscalltab+0(3) = '226'.
success_226 = 'X'.
ENDIF.
ENDLOOP.
ENDFUNCTION.
*-----------------------------------------------------------
FUNCTION Z_FTP_DOWNLOAD.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(SRC_FILE)
*" REFERENCE(DEST_FILE)
*" REFERENCE(FTP_SERVER)
*" REFERENCE(FTP_USER)
*" REFERENCE(FTP_PASSWD)
*" REFERENCE(FLAG_BINARY) OPTIONAL
*" EXPORTING
*" REFERENCE(SUCCESS_226)
*" TABLES
*" OUTPUT
*" EXCEPTIONS
*" COULD_NOT_OPEN_COMMANDFILE
*"----------------------------------------------------------------------
*-----------------------------------------------------------------------
* DATENDEFINITION
*-----------------------------------------------------------------------
DATA: uuid LIKE sysuuid-c.
DATA: dsn TYPE string.
DATA: fl TYPE string.
DATA: os_command(500).
DATA: BEGIN OF syscalltab OCCURS 0,
line(200),
END OF syscalltab.
* Temporären Dateiname ermitteln.
" UUID erstellen
CALL FUNCTION 'SYSTEM_UUID_C_CREATE'
IMPORTING
uuid = uuid.
CONCATENATE '/tmp/ftp_' uuid INTO dsn.
* FTP Kommandofile schreiben
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0. RAISE could_not_open_commandfile. ENDIF.
CONCATENATE 'user' ftp_user ftp_passwd
INTO fl SEPARATED BY space.
TRANSFER fl TO dsn.
IF flag_binary NE space.
TRANSFER 'binary' TO dsn.
ENDIF.
CONCATENATE 'put' src_file dest_file INTO fl SEPARATED BY space.
TRANSFER fl TO dsn.
TRANSFER 'bye' TO dsn.
CLOSE DATASET dsn.
* Betriebssystemkommando erstellen.
CONCATENATE 'ftp -n -v' ftp_server '<' dsn
INTO os_command SEPARATED BY space.
CALL 'SYSTEM'
ID 'COMMAND'
FIELD os_command
ID 'TAB'
FIELD syscalltab-*sys*.
MOVE syscalltab[] TO output[].
* temporäres File wieder löschen.
DELETE DATASET dsn.
* Ftp Rückmeldungen auswerten
* 226 bedeutet File erfolgreich übertragen
LOOP AT syscalltab.
IF syscalltab+0(3) = '226'.
success_226 = 'X'.
ENDIF.
ENDLOOP.
ENDFUNCTION.
Das ist nur eins der Probleme, s. auch meine Antwort zu Deinem anderen Tipp:stele hat geschrieben:Diesee Funktionsbausteine können FTP Uploads und Downloads durchführen. Sie Nutzen die Funktion Betriebsystemkommandos auszuführen.
Setzen Sie SAP auf anderen Betriebsystemem müssen Sie den Systemcommand evlt. noch etwas anpassen.
Code: Alles auswählen.
FUNCTION Z_ftp_upload.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(SRC_FILE)
*" REFERENCE(DEST_FILE)
*" REFERENCE(FTP_SERVER)
*" REFERENCE(FTP_USER)
*" REFERENCE(FTP_PASSWD)
*" REFERENCE(FLAG_BINARY) OPTIONAL
*" EXPORTING
*" REFERENCE(SUCCESS_226)
*" TABLES
*" OUTPUT
*" EXCEPTIONS
*" COULD_NOT_OPEN_COMMANDFILE
*"----------------------------------------------------------------------
*-----------------------------------------------------------------------
* DATENDEFINITION
*-----------------------------------------------------------------------
DATA: uuid LIKE sysuuid-c.
DATA: dsn TYPE string.
DATA: fl TYPE string.
DATA: os_command(500).
DATA: BEGIN OF syscalltab OCCURS 0,
line(200),
END OF syscalltab.
*Temporärer Dateiname ermitteln.
" 1. UUID erstellen
CALL FUNCTION 'SYSTEM_UUID_C_CREATE'
IMPORTING
uuid = uuid.
CONCATENATE '/tmp/ftp_' uuid INTO dsn.
* FTP Kommandofile schreiben
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
Code: Alles auswählen.
IF sy-subrc NE 0. RAISE could_not_open_commandfile. ENDIF.
CONCATENATE 'user' ftp_user ftp_passwd
INTO fl SEPARATED BY space.
TRANSFER fl TO dsn.
Code: Alles auswählen.
IF flag_binary NE space.
TRANSFER 'binary' TO dsn.
ENDIF.
CONCATENATE 'put' src_file dest_file INTO fl SEPARATED BY space.
Für FTP gibt es von SAP aus eine weit bessere Möglichkeiten mittels RFC-Aufrufen. Und das für Präsentations- und Applicationserver.Diesee Funktionsbausteine können FTP Uploads und Downloads durchführen. Sie Nutzen die Funktion Betriebsystemkommandos auszuführen.