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

Problems with FTP_SERVER_TO_R3

Former Member
0 Likes
1,498

i am trying to use FTP to bring a text file from an FTP server to an internal table.

we had to apply an OSS notethat allowed us to use the "character_mode" switch.

The problem is, when i use charactermode = 'X' and supply a table for the TEXT parameter, i get NOTHING in the text table. I still get data in the BLOB table (i have to pass this becuase it is not optional), but nothing in the TEXT table.

The BLOB table does not separate the data based on CRLF, which is what i am looking for.

I checked prior messages, and OSS, without much luck.

i am trying to use FTP to bring a text file from an FTP server to an internal table.

we had to apply an OSS notethat allowed us to use the "character_mode" switch.

The problem is, when i use charactermode = 'X' and supply a table for the TEXT parameter, i get NOTHING in the text table. I still get data in the BLOB table (i have to pass this becuase it is not optional), but nothing in the TEXT table.

The BLOB table does not separate the data based on CRLF, which is what i am looking for.

I checked prior messages, and OSS, without much luck.

2 REPLIES 2
Read only

Former Member
0 Likes
897

Hi David:

I am assuming your SAP System runs on Windows NT.

If you are looking to get a text file from FTP Server to an Internal Table, I would suggest first transfer the file to a location in your SAP App Server.You can use FMs FTP_CONNECT,FTP_COMMAND,FTP_CLOSE.Then read the file from your SAP App. Server in to a ITAB using DATASET Commands(Open Dataset, Transfer Dataset).Then on successfull read Delete the dataset in the App Server.

Here is the code to FTP a file from a remote FTP server to SAP App Server.

l_filespec - SAP App server file path

r_filespec - FTP Server file path

In your code, use the RFC Destination 'sapftp' and it will be generated automatically when it establishes the first connection.Also make sure FTP Service is running in your FTP Server and you use the right user id / password / domain for logon and you have read/write access to the folder from which the file needs to be fetched.

*********************************************************

FUNCTION Z_EXEC_SIMPLE_FTP.

*"----


""Local interface:

*" IMPORTING

*" VALUE(I_REMOTE_HOST) TYPE C

*" VALUE(I_USERID) TYPE C DEFAULT SPACE

*" VALUE(I_PASSWORD) TYPE C DEFAULT SPACE

*" VALUE(I_LOCAL_PATH) TYPE C DEFAULT SPACE

*" VALUE(I_LOCAL_FILE) TYPE C DEFAULT SPACE

*" VALUE(I_REMOTE_PATH) TYPE C DEFAULT SPACE

*" VALUE(I_REMOTE_FILE) TYPE C DEFAULT SPACE

*" VALUE(I_PUT_TO_REMOTE_HOST) TYPE C DEFAULT SPACE

*" VALUE(I_DESTINATION) LIKE RFCDES-RFCDEST DEFAULT 'SAPFTP'

*" TABLES

*" DATA

*" EXCEPTIONS

*" NOT_CONNECTED

*" TCPIP_ERROR

*" COMMAND_ERROR

*" DATA_ERROR

*"----


DATA: MC_PASSWORD(20) TYPE C,

MI_KEY TYPE I VALUE 26101957,

MI_PWD_LEN TYPE I.

MC_PASSWORD = I_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.

*Set FTP File Paths

CONCATENATE i_local_path i_local_file INTO l_filespec.

CONCATENATE i_remote_path i_remote_file INTO r_filespec.

----


*FTP Connect

----


CALL FUNCTION 'FTP_CONNECT'

EXPORTING

USER = I_USERID

PASSWORD = MC_PASSWORD

ACCOUNT = '<Your Domain Name>'

HOST = I_REMOTE_HOST

RFC_DESTINATION = I_DESTINATION

IMPORTING

HANDLE = FTP_HANDLE

EXCEPTIONS

NOT_CONNECTED = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO WITH

SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4

RAISING NOT_CONNECTED.

ENDIF.

----


----


*FTP Command

----


  • Get without semaphore...

CONCATENATE 'get' r_filespec l_filespec

INTO l_command SEPARATED BY space.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = ftp_handle

command = l_command

TABLES

data = T_FTP_RESPONSE

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

----


*FTP Close

----


  • Close Connection

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = ftp_handle

EXCEPTIONS

OTHERS = 1.

ENDFUNCTION.

Read only

STALANKI
Active Contributor
0 Likes
897

Hi,

I want to download the file from FTP server to APP server.

I have used FTP FM for doing the same.The problem is when am using get command and want to specify the path in appserver..it is giving me an error path not found error?Can anyone give me more info?Is the file gets downloaded to any default directory in appserver?If yes can u plz help?