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

Transfer a xml file from application server to another server using FTP

Former Member
0 Likes
2,437

Hi experts,

I am stuck in this situtaion.

My interface generates a xml file on an application server.

Now i need to read the xml file generated and transfer it to another system using FTP.

I can use READ DATASET to read the file from the application server.

And use the below function modules to transfer it to another system

HTTP_SCRAMBLE.

FTP_CONNECT

CONCATENATE 'put' src_file_dest into variable.

FTP_COMMAND with command = variable.

FTP_DISCONNECT.

Now my question is:

- Is it correct????

- I am getting an cerror = 3 while using FTP_CONNECT. is it an authorization issue???

if yes, what is the issue???

- How to connect the file read from READ DATASET to the FTP Function Modules ????

Thanks and Regards

Gaurav Raghav

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,630

Try the following set of FTP commands..

This code gets the file (NOT the content) from the server and sends it to the FTP.




*********start send file to FTP********************
* FTP commands : 1. ascii
*       2. cd 
*       3. lcd
*       4. put 



call function 'HTTP_SCRAMBLE'
    exporting
      source      = x_pwd
      sourcelen   = dstlen
      key         = key
    importing
      destination = destin.

  clear pass.
  pass = destin.


  call function 'FTP_CONNECT'
       exporting
            user            = x_user
*            PASSWORD       = X_PWD
            password        = pass
            host            = x_host
            rfc_destination = x_dest
       importing
            handle          = hdl.


*  COMMAND ascii -->
  refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_ascii
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.




*command cd SAP\ -->
  split x_file at '\' into dummy ftp_file.
  concatenate x_cmd1 dummy into dummy2 separated by space.
  concatenate dummy2 '\' into cmd_cd.
  refresh : x_result.

  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_cd
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.

 constants: winslash(1)   value  '\',
            unixslash(1)  value  '/'.

 call 'C_SAPGPARAM' id 'NAME'  field 'DIR_HOME'
                     id 'VALUE' field  tempdir.



* command lcd SERVER\usr\....\DIR_HOME --?
concatenate 'lcd' tempdir into cmd_lcd separated by space.
refresh : x_result.
 call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_lcd
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


* COMMAND put file -->
concatenate 'put' ftp_file into cmd_put separated by space.
 refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_put
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


* command ls -->
  refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd2
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


  call function 'FTP_DISCONNECT'
    exporting
      handle = hdl.
******* end send file to FTP*****

Edited by: Iria Koutsogianni on Jan 19, 2009 11:50 AM

Hi experts,

I am stuck in this situtaion.

My interface generates a xml file on an application server.

Now i need to read the xml file generated and transfer it to another system using FTP.

I can use READ DATASET to read the file from the application server.

And use the below function modules to transfer it to another system

HTTP_SCRAMBLE.

FTP_CONNECT

CONCATENATE 'put' src_file_dest into variable.

FTP_COMMAND with command = variable.

FTP_DISCONNECT.

Now my question is:

- Is it correct????

- I am getting an cerror = 3 while using FTP_CONNECT. is it an authorization issue???

if yes, what is the issue???

- How to connect the file read from READ DATASET to the FTP Function Modules ????

Thanks and Regards

Gaurav Raghav

11 REPLIES 11
Read only

Former Member
0 Likes
1,631

Try the following set of FTP commands..

This code gets the file (NOT the content) from the server and sends it to the FTP.




*********start send file to FTP********************
* FTP commands : 1. ascii
*       2. cd 
*       3. lcd
*       4. put 



call function 'HTTP_SCRAMBLE'
    exporting
      source      = x_pwd
      sourcelen   = dstlen
      key         = key
    importing
      destination = destin.

  clear pass.
  pass = destin.


  call function 'FTP_CONNECT'
       exporting
            user            = x_user
*            PASSWORD       = X_PWD
            password        = pass
            host            = x_host
            rfc_destination = x_dest
       importing
            handle          = hdl.


*  COMMAND ascii -->
  refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_ascii
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.




*command cd SAP\ -->
  split x_file at '\' into dummy ftp_file.
  concatenate x_cmd1 dummy into dummy2 separated by space.
  concatenate dummy2 '\' into cmd_cd.
  refresh : x_result.

  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_cd
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.

 constants: winslash(1)   value  '\',
            unixslash(1)  value  '/'.

 call 'C_SAPGPARAM' id 'NAME'  field 'DIR_HOME'
                     id 'VALUE' field  tempdir.



* command lcd SERVER\usr\....\DIR_HOME --?
concatenate 'lcd' tempdir into cmd_lcd separated by space.
refresh : x_result.
 call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_lcd
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


* COMMAND put file -->
concatenate 'put' ftp_file into cmd_put separated by space.
 refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd_put
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


* command ls -->
  refresh : x_result.
  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = cmd2
      compress      = compress
    tables
      data          = x_result
    exceptions
      command_error = 1
      tcpip_error   = 2.


  call function 'FTP_DISCONNECT'
    exporting
      handle = hdl.
******* end send file to FTP*****

Edited by: Iria Koutsogianni on Jan 19, 2009 11:50 AM

Read only

0 Likes
1,630

Hi Iria,

I need to send the file as well as the content to the server.

Thanks and Regards

Gaurav Raghav

Read only

Former Member
0 Likes
1,630

Hi!!

The content is also transfered, what i meant is that with this code it's like copy the file from the server & paste it to the FTP.

Try it and let me know!

Read only

0 Likes
1,630

Hi Iria,

I will try and let you know.

One more thing, how can we generate multiple files on the application server.

I am using open and close dataset inside a loop.

but it is not working.

Thanks and Regards

Gaurav raghav

Read only

Former Member
0 Likes
1,630

Normally it should work, but how do u transfer data to the files??

Please provide the code here so i can understand the problem.

Read only

0 Likes
1,630

Hi Iria,

It is working fine now.

I had added a Count so the files were not coming together at the end.

Sorry for the silly issue.

Thanks and Regards

Gaurav raghav

Read only

Former Member
0 Likes
1,630

There are no "silly" questions..

Let me know if u get the FTP code to work.

Regards,

Iria

Read only

0 Likes
1,630

I am working on it.

Will let you know asap.

thanks

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,630

Hello Gaurav

If you want to transfer files from one SAP application server to another SAP application server then I like to (ab)use the fm EPS_FTP_PUT. All you need is a RFC destination between the two systems.

Regards

Uwe

Read only

0 Likes
1,630

Hi Uwe,

I need to transfer file to a Non-SAP server.

Thanks and REgards

Gaurav Raghav

Read only

Former Member
0 Likes
1,630

Hi Iri,

I got it resolved by using Report RSFTP002.

I was not able to figure out how to use it before.

It has the same functionality.

Thanks and Regards

Gayurav raghav