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

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.....

6 REPLIES 6

FredericGirod
Active Contributor

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

former_member329386
Participant
0 Kudos

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

Hello,

Can you try this ARCHIVFILE_SERVER_TO_SERVER function?

Sandra_Rossi
Active Contributor
0 Kudos

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

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

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.