Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&---------------------------------------------------------------------*
- *& Report Z_FTP_CONNECTION_TEST
- *&
- *&---------------------------------------------------------------------*
- *& Little check to see if FTP Server is handling unicode commands correctly.
- *&
- *&---------------------------------------------------------------------*
- REPORT z_ftp_connection_test.
- DATA: hdl TYPE i,
- key TYPE i VALUE 26101957,
- slen TYPE i,
- result TYPE TABLE OF text255 WITH HEADER LINE,
- pwd_scr TYPE zftppass.
- DATA: gv_subrc TYPE sy-subrc,
- gv_folder type char100,
- lv_command TYPE char120,
- lv_command_len TYPE i,
- lv_command_hex TYPE char120.
- SELECTION-SCREEN BEGIN OF BLOCK login WITH FRAME TITLE text-100.
- PARAMETERS: user TYPE zftpuser LOWER CASE,
- pwd TYPE zftppass LOWER CASE,
- host TYPE zfserver_zs LOWER CASE.
- SELECTION-SCREEN SKIP 1.
- PARAMETERS: dest LIKE rfcdes-rfcdest.
- SELECTION-SCREEN SKIP 1.
- SELECTION-SCREEN END OF BLOCK login.
- CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
- EXPORTING
- text = 'Running FTP test'.
- "++++++++++++++++++++++++++++++++++++++ STEP 1
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 1'.
- WRITE: / 'This step just connects to the FTP Server'.
- lv_command = 'FTP_CONNECT'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- slen = strlen( pwd ).
- CALL FUNCTION 'HTTP_SCRAMBLE'
- EXPORTING
- source = pwd
- sourcelen = slen
- key = key
- IMPORTING
- destination = pwd_scr.
- CALL FUNCTION 'FTP_CONNECT'
- EXPORTING
- user = user
- password = pwd_scr
- host = host
- rfc_destination = dest
- IMPORTING
- handle = hdl
- EXCEPTIONS
- not_connected = 99.
- IF sy-subrc = 99.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Cannot connect'.
- PERFORM close.
- EXIT.
- ELSE.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Looks like we are connected'.
- ENDIF.
- "++++++++++++++++++++++++++++++++++++++ STEP 2
- " Commands
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 2'.
- WRITE: / 'This step sends a valid FTP request'.
- lv_command = 'cd /test'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- "Verify test environment exists
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE: / result.
- ENDLOOP.
- FIND '550' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Folder does not exists. need to check'.
- PERFORM close.
- exit.
- ELSE.
- FIND '250' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Test environment ok'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Unexpected result. Closing'.
- PERFORM close.
- exit.
- ENDIF.
- ENDIF.
- "++++++++++++++++++++++++++++++++++++++ STEP 3
- " Commands
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 3'.
- WRITE: / 'This step sends a valid FTP request'.
- lv_command = 'set passive on'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- gv_subrc = sy-subrc.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE: / result.
- ENDLOOP.
- IF gv_subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'FTP responded normally'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'FTP not responding'.
- "EXIT.
- ENDIF.
- "++++++++++++++++++++++++++++++++++++++ STEP 4
- " Create Chinese folder
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 4'.
- WRITE: / 'This step wants to create a folder with chinese symbols'.
- lv_command = 'mkd 汉语'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- gv_subrc = sy-subrc.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE: / result.
- ENDLOOP.
- FIND '257' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Folder 汉语 might have been created.. need to check'.
- ELSE.
- FIND '550' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Folder 汉语 already exist. Please delete first'.
- PERFORM close.
- EXIT.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Folder 汉语 could not be created, try system call'.
- ENDIF.
- ENDIF.
- "++++++++++++++++++++++++++++++++++++++ STEP 5
- " Read wrong Chinese folder
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 5'.
- WRITE: / 'This step reads a DIFFERENT folder, must not work to be successfull (negativ test)'.
- lv_command = 'cd 语汉'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE / result.
- ENDLOOP.
- FIND '550' IN TABLE result. " .. is not a directory
- IF sy-subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Folder could not be read, looks good'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Folder could be read anyway? WRONG!'.
- ENDIF.
- "Back to root
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = 'cd /test'
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- "++++++++++++++++++++++++++++++++++++++ STEP 6
- " Read correct Chinese folder
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 6'.
- WRITE: / 'Doublecheck, now we read the folder we just created (positiv test)'.
- lv_command = 'cd 汉语'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- gv_subrc = sy-subrc.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE / result.
- ENDLOOP.
- FIND '250' IN TABLE result.
- IF gv_subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Correct Chinese folder could be read'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Folder could not be read'.
- " EXIT.
- ENDIF.
- "Back to test
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = 'cd /test'
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- "++++++++++++++++++++++++++++++++++++++ STEP 7
- " Read the folder name
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 7'.
- WRITE: / 'Now we try to read the folders name (so we can cd into it)'.
- lv_command = 'ls'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- gv_subrc = sy-subrc.
- WRITE: / 'Detail:'.
- LOOP AT result.
- FIND REGEX '(d[rwx-]{9})' IN result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE: / result(70), '<-- this must be a folder'..
- gv_folder = result+49(100).
- ELSE.
- FORMAT COLOR OFF.
- WRITE / result.
- ENDIF.
- ENDLOOP.
- "++++++++++++++++++++++++++++++++++++++ STEP 8
- "Navigating into the found folder:
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 8'.
- WRITE: / 'Now lets navigate into that folder'.
- lv_command = 'cd /test/' && gv_folder.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- WRITE: / 'Detail:'.
- LOOP AT result.
- write / result.
- endloop.
- FIND '250' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Directory Change successful'.
- ELSE.
- FIND '550' IN TABLE result.
- IF sy-subrc = 0.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Error entering the folder.'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Unexpected error'.
- ENDIF.
- PERFORM close.
- exit.
- ENDIF.
- PERFORM close.
- *&---------------------------------------------------------------------*
- *& Form close
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- FORM close.
- "++++++++++++++++++++++++++++++++++++++ STEP 9 Cleanup
- FORMAT RESET.
- WRITE: / '---------------'.
- WRITE: / 'STEP 9'.
- WRITE: / 'Cleanup'.
- lv_command = 'cd /test'.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- "Back to root
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- lv_command = 'rmd 汉语'.
- FORMAT RESET.
- WRITE: / 'COMMAND: ', lv_command.
- REFRESH result.
- CALL FUNCTION 'FTP_COMMAND'
- EXPORTING
- handle = hdl
- command = lv_command
- TABLES
- data = result
- EXCEPTIONS
- OTHERS = 1.
- gv_subrc = sy-subrc.
- WRITE: / 'Detail:'.
- LOOP AT result.
- WRITE: / result.
- ENDLOOP.
- IF gv_subrc = 0.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'FTP responded normally'.
- ELSE.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'FTP not responding'.
- ENDIF.
- CALL FUNCTION 'FTP_DISCONNECT'
- EXPORTING
- handle = hdl.
- CALL FUNCTION 'RFC_CONNECTION_CLOSE'
- EXPORTING
- destination = dest
- EXCEPTIONS
- OTHERS = 99.
- IF sy-subrc = 99.
- FORMAT COLOR COL_NEGATIVE.
- WRITE / 'Connection could not be closed'.
- ELSE.
- FORMAT COLOR COL_POSITIVE.
- WRITE / 'Connection closed'.
- ENDIF.
- ENDFORM. "close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement