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

FTP Commands

Former Member
0 Likes
1,587

Hello Everyone,

I need to connect to another server via FTP, and I am using FTP_CONNECT for that. After connection is established, I need to get the file based on the directory. How do I do that? I found FM FTP_COMMAND, but what command should I use?

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

  • HANDLE =

command =

  • COMPRESS =

  • RFC_DESTINATION =

  • VERIFY =

  • IMPORTING

  • FILESIZE =

  • FILEDATE =

  • FILETIME =

tables

data =

  • EXCEPTIONS

  • TCPIP_ERROR = 1

  • COMMAND_ERROR = 2

  • DATA_ERROR = 3

  • OTHERS = 4

  • .

What value should I pass to each field?

Thanks,

Louisse

1 ACCEPTED SOLUTION
Read only

0 Likes
949

Go through this blog.

Link : [https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/4743] [original link is broken] [original link is broken] [original link is broken];

Result_itab will have values like

1.FTP is connected

2.local directory has been changed

3.File has been placed.

This approach is used to get the file from legacy and put it into application server then you can read the file with Open dataset and read dataset command.

Rajesh Pichholiya

3 REPLIES 3
Read only

Former Member
0 Likes
949

hi,



*--> Scramble the password.

CALL FUNCTION 'SCRAMBLE_STRING'
EXPORTING
source = password
key = 26101957
IMPORTING
target = password.

*--> Connect to the FTP server.

* user is the logon user for the FTP server.


password is the password you have just scrambled. 
host is the ip address of the FTP server. 
rfc_destination is 'SAPFTPA'. 

CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = password
host = host
rfc_destination = rfc_destination
IMPORTING
handle = wa_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2.

*--> Carry out the command on the FTP server

* wa_command is the command you wish to carry out on the FTP server (e.g. 


wa_command = 'ascii' will specify ascii mode). Result_itab will contain the 
result of your commands. 
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = wa_handle
command = wa_command
TABLES
data = result_itab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.



*--> Disconnect from the target host.

CHECK NOT wa_handle IS INITIAL.

CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = wa_handle
EXCEPTIONS
OTHERS = 1.



The IMPORT parameters are as :

USER i.e the userid

PASSWORD,

HOST i.e the FTP server

RFC_DESTINATION ( the parameter passed corresponding to this must be of type RFCDES_RFCDEST ).

All these IMPORT parameters except RFC_DESTINATION are of TYPE C.

The EXPORT parameter is the

HANDLE ( this identifies the FTP connection ). Its of TYPE I.

Hope this helps

Edited by: Runal Singh on Apr 2, 2008 2:40 PM

Read only

0 Likes
949

Hello,

Thanks for your prompt reply. I would just like to confirm that if I put a value of ASCII to wa_command parameter of FM FTP_COMMAND, will this retrieve the files from the server? And that the file will be stored in internal table result_itab?

Thanks,

Louisse

Read only

0 Likes
950

Go through this blog.

Link : [https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/4743] [original link is broken] [original link is broken] [original link is broken];

Result_itab will have values like

1.FTP is connected

2.local directory has been changed

3.File has been placed.

This approach is used to get the file from legacy and put it into application server then you can read the file with Open dataset and read dataset command.

Rajesh Pichholiya