Application Development 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: 

Move / Copy file from one folder to another folder

former_member329386
Participant
0 Kudos
1,503

I want to copy the file from one folder to another.

I am using SAPFTPA.

these function modules are used Function module used CALL FUNCTION 'HTTP_SCRAMBLE' , CALL FUNCTION 'FTP_CONNECT',

CALL FUNCTION 'FTP_COMMAND' , CALL FUNCTION 'FTP_SERVER_TO_R3'

. The path D:\Sales\Macine\Product\fail_log contains file test.csv

and i want to move test.csv file to another path D:\Sales\Macine\Product\fail_log_n

can any one guide me.....

8 REPLIES 8

FredericGirod
Active Contributor
1,396

The file is in presentation server or Application server ? Why do you used FTP command for non FTP protocol ?

former_member329386
Participant
0 Kudos
1,396

frdric.girod

We have third party integration process about sales data. the third party is send files on ftp server (with ip ).

Our program picking the files from that path , reading it and then deleting files .

But before deleting these file we want the copy of this file on another folder for backup purpose,

Thank you

abityildiz
Active Participant
0 Kudos
1,396

Hello,

Can you try this ARCHIVFILE_SERVER_TO_SERVER function?

Sandra_Rossi
Active Contributor
0 Kudos
1,396

You can use the FTP command "rename" (via function module FTP_COMMAND), which also works for moving.

CALL FUNCTION 'FTP_COMMAND'
       EXPORTING
         handle        = ftp_handle
         command       =
'rename D:\Sales\Macine\Product\fail_log\test.csv D:\Sales\Macine\Product\fail_log_n\test.csv'
       TABLES
         data          = result
       EXCEPTIONS
         command_error = 1 
         tcpip_error   = 2.

NB: don't forget to wrap it will all classic calls to HTTP_SCRAMBLE, FTP_CONNECT and FTP_DISCONNECT of course.

0 Kudos
1,396

There is one issue that i missed in my first query ....The third party software placing the file after one hour scheduling and file is placing with naming

D:\Sales\Macine\Product\fail_log\test_16.01.2023_15.30.22.

D:\Sales\Macine\Product\fail_log\test_16.01.2023_16.30.22. and so on ...

I have to pick all the files . so i cannot use rename D:\Sales\Macine\Product\fail_log\test.csv D:\Sales\Macine\Product\fail_log_n\test.csv' so cannot fix the file name.

Before reading the files from folder i have to keep the backup of all files from this folder.

Thank you.

0 Kudos
1,396

So, I answered your question and future visitors will find the answer how to move a file (in FTP).

But you have other questions, not sure, please clarify:

  1. How to copy from server to server? (you probably know how to read and write files from your ABAP program to internal table, so I guess you need server to server) There is no specific FTP command, but maybe you could use directly an Operating System command like command = '!cp frompath topath'
  2. How to get the list of file names in one folder? command = 'dir folder' (for instance)
  3. How to move all the files in bulk? You can't, you can do it file by file (or command = 'del targetfolder', then 'rename sourcefolder targetfolder', then 'mkdir sourcefolder', but you would experience authorization issues probably)

NB: in command, you can indicate a variable for the command parameter, so you can indicate any file name you want at runtime.

0 Kudos
523

CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_ftp_handle
command = 'RNFR D:\Sales\Macine\Product\fail_log\test.csv'
IMPORTING
reply = lv_reply.CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_ftp_handle
command = 'RNTO D:\Sales\Macine\Product\fail_log_n\test.csv'
IMPORTING
reply = lv_reply.                                                                                                                                          

I also have a similar requirement. the thing is this is rename right. my lead says we dont have the authorization to rename. we need to transfer files among two folders within same ftp, server  read and copy to another program. Is there any way.

Sandra_Rossi
Active Contributor
0 Kudos
486

Please post a new question here and see also the List of FTP commands - Wikipedia (mainly RFC 959).