08-03-2006 5:38 PM
Dear Sirs, we have to send a text file from our sap application server (45B on unix) to a ftp server on windows.
1)First we try to use the FTP_R3_TO_SERVER like this:
call function 'FTP_R3_TO_SERVER'
exporting
handle = g_handle
fname = p_file
blob_length = l_blob_lenght
tables
blob = pt_file
exceptions
tcpip_error = 1
command_error = 2
data_error = 3
others = 4
Where pt_file is a internal table filled with content of
the file declared like this:
data: begin of it_file occurs 0,
rec(80),
end of it_file.
The files arrives on the destination, but is empty.
2)After we try to use the FTP_COMMAND like the RSFTP002 program, but our source file is on application server so my command is like this
put /usr/sap/D41/SYS/global/abc.txt
The command runs but the log displays
"The system cannot find the path specified".
Notice that FTP_CONNECT
and other ftp commands like cd <dir> works well.
Have you some to suggest ?
Best Regards.
Riccardo Galli
08-03-2006 6:02 PM
hi,
try using open dataset file for output in text mode encoding default..it works easily..
08-03-2006 6:09 PM
Hi,
Use FTP_CONNECT, FTP_COMMAND, FTP_DISCONNECT functions....
put RSFTP* in se38 and u will see some example programs...the only thing u need to know is how to specify the path....application server path looks like \sapmnt\ etc .. go to AL11 and see how paths are specified... in addition if u r transferring from local machine...then u can specify c:\tmp\ftpfile.txt etc
<u><b>The below is a Sample program,</b></u>
code]
SAP FTP functions
This sample program will logged into your Unix Server.
Issue a Unix dir command
Store the dir information in the Internal table and
display it.
Make sure you can telnet in to your SAP-UNIX FTP server * first.
Written by : SAP Basis, ABAP Programming and Other IMG * Stuff
*
REPORT ZFTPSAP LINE-SIZE 132.
<b>DATA: BEGIN OF MTAB_DATA OCCURS 0,
LINE(132) TYPE C,
END OF MTAB_DATA.</b>
DATA: MC_PASSWORD(20) TYPE C,
MI_KEY TYPE I VALUE 26101957,
MI_PWD_LEN TYPE I,
MI_HANDLE TYPE I.
START-OF-SELECTION.
*-- Your SAP-UNIX FTP password (case sensitive)
MC_PASSWORD = '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.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
*-- Your SAP-UNIX FTP user name (case sensitive)
USER = 'userid'
PASSWORD = MC_PASSWORD
*-- Your SAP-UNIX server host name (case sensitive)
HOST = 'unix-host'
RFC_DESTINATION = 'SAPFTP'
IMPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
NOT_CONNECTED = 1
OTHERS = 2.
CHECK SY-SUBRC = 0.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = MI_HANDLE
COMMAND = 'dir'
TABLES
<b> DATA = MTAB_DATA</b>
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF SY-SUBRC = 0.
LOOP AT MTAB_DATA.
WRITE: / MTAB_DATA.
ENDLOOP.
ELSE.
do some error checking.
WRITE: / 'Error in FTP Command'.
ENDIF.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
OTHERS = 1. [/code]
Here internal table is <b>MTAB_DATA</b> will have the Data, so Use the Datasets(OPEN DATASET,READ and CLOSE DATASETS) to get the Data ftom the Application Server to the Internal Table
hope that helps..
Thanks
Sudheer
08-03-2006 9:23 PM
Thanks for your answer
The connection fpt works well, and also other
ftp commands like 'cd' or 'dir'.
I use a SAPFTPA rfc destination beacause
the program haves to run also in bkgr.
But problem is when i try to run the command 'put'.
I want to put a file resident on my sap application server
to a taget ftp directory (IIS windows server).
In AL11 my file is dispayed like (unix)
/usr/sap/d41/home/abc.txt
so my command is (i suppose)
zcommand = 'put /usr/sap/d41/home/abc.txt'
If i try to run this command:
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = MI_HANDLE
COMMAND = zcommand
TABLES
DATA = MTAB_DATA
the mtab_data returns the string
"The system cannot find the path specified"
What is wrong ?
Thanks Riccardo
08-03-2006 9:42 PM
when you login, you will be logged into your home directory which may or may not be "/usr/sap/d41/home/". So you need to do a "cd /usr/sap/d41/home/" first and then do your 'put' command.
04-20-2007 5:12 PM
Hi Ricardo
Were you able to find a solution. I am having the same issue. I am trying to put a file onto an external FTP server using SAPFTPA and am unable to connect but I can connect and use drop the file using SAPFTP.
Regarding your put syntax problem. I had the same issue. The file that you want to put onto the external ftp server needs to be in the local directory. To find out the local directory do lcd. Then move your file to that directory. Then you can do put filename and it will drop the file