FTP Server to Server file transfter
I am using Apache common.net package 2.0 for my FTP file transfer from one server to another server. And i'm using eclipse 3.3.2 IDE for my code execution.
Following is the function i'm using for ftp to ftp file transfer.
public void severtoservercopyfile()
FTPClient ftpClient1 = new FTPClient();
FTPClient ftpClient2 = new FTPClient();
ProtocolCommandListener listener;
try
listener = new PrintCommandListener(new PrintWriter(System.out));
ftpClient1.addProtocolCommandListener(listener);
ftpClient2.addProtocolCommandListener(listener);
System.out.println("Connecting FTP1 ");
ftpClient1.connect("ftp.xxxx.com");
ftpClient1.login("demo", "demo");
if (!FTPReply.isPositiveCompletion(ftpClient1.getReplyCode())) {
String errMsg = "User : ftp1 server could not connect. FTP server refused connection.";
System.out.println(errMsg);
System.out.println("Connecting FTP2 ");
ftpClient2.connect("xx.xx.xxx.xx");
ftpClient2.login("username", "password");
if (!FTPReply.isPositiveCompletion(ftpClient2.getReplyCode())) {
String errMsg = "User : could not connect. FTP2 server refused connection.";
System.out.println(errMsg);
String fromPath = "/PPP/Test/";
String toPath = "/testprojects/PPP/Test/";
String file1 = "2009121.xml";
String file2 = "2009121.xml";
int replyCode = ftpClient1.cwd(fromPath);
System.out.println("replyCode 1 : "+replyCode);
if (!FTPReply.isPositiveCompletion(replyCode)) {
String errMsg = "Could not change to directory : "
+ fromPath;
System.out.println(errMsg);
int replyCode2 = ftpClient2.cwd(toPath);
System.out.println("replyCode 2 : "+replyCode2);
if (!FTPReply.isPositiveCompletion(replyCode2)) {
String errMsg = "Could not change to directory : "
+ toPath;
System.out.println(errMsg);
//_main:
try{
boolean isPassive = ftpClient2.enterRemotePassiveMode();
boolean isActive = false;
if(isPassive){
System.out.println("FtpClient2 is in Passive mode");
System.out.println("FtpClient2 Host : "+ftpClient2.getPassiveHost());
System.out.println("FtpClient2 Port : "+ftpClient2.getPassivePort());
System.out.println("FtpClient1 is entering RemoteActive Port : ");
isActive = ftpClient1.enterRemoteActiveMode(InetAddress.getByName(ftpClient2.getPassiveHost()), ftpClient2.getPassivePort());
if(isActive)
System.out.println("FtpClient1 is in Active mode");
else
System.out.println("FtpClient1 is NOT in Active mode");
System.out.println(" FtpClient1 Remote verification : "+ftpClient1.isRemoteVerificationEnabled());
System.out.println(" FtpClient2 Remote verification : "+ftpClient2.isRemoteVerificationEnabled());
else
System.out.println("FtpClient2 is NOT in Passive mode");
/*boolean remoteRet = ftpClient1.remoteRetrieve(file1);
boolean remoteStore = ftpClient2.remoteStoreUnique(file2);
ftpClient1.completePendingCommand();
ftpClient2.completePendingCommand();
System.out.println("FtpClient1 remote Retrive "+remoteRet);
System.out.println("FtpClient2 remote Store "+remoteStore);*/
if (ftpClient1.remoteRetrieve(file1) && ftpClient2.remoteStoreUnique(file2))
System.out.println("File Transferring ...");
//if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
// We have to fetch the positive completion reply.
ftpClient1.completePendingCommand();
ftpClient2.completePendingCommand();
else
System.out.println("Couldn't initiate transfer. Check that filenames are valid.");
//break _main;
} catch(Exception e){
System.out.println(replyCode);
System.out.println("Disconnecting FTP1");
ftpClient1.disconnect();
System.out.println("Disconnecting FTP2");
ftpClient2.disconnect();
System.out.println("Finished FTP");
} catch(Exception e){
System.out.println("Exception Occured");
if (ftpClient1.isConnected())
try
ftpClient1.disconnect();
catch (IOException f)
// do nothing
if (ftpClient2.isConnected())
try
ftpClient2.disconnect();
catch (IOException f)
// do nothing
System.out.println("Error : "+e);
}I'm getting the error "425: Can't build data connection" and part of my console display is
FtpClient1 is in Active mode
FtpClient1 Remote verification : true
FtpClient2 Remote verification : true
RETR 2009121.xml
150 Opening BINARY mode data connection for 2009121.xml (543 bytes).
STOU 2009121.xml
425: Can't build data connection.
Couldn't initiate transfer. Check that filenames are valid.
250
Can anybody tell me how to overcome this error and make this code to run successfully.
Seems to me to be a firewall issue. See if you can connect via a command line tool and do the transfer in passive mode. (Get from one server and put on the other). If that works, then duplicate what you did in Java. If it is a firewall issue, your command line usage will fail as well. My strong suspicion is that you do not want to use active mode.
http://slacksite.com/other/ftp.html
- Saish
Similar Messages
-
In FTP server file not storing in proper order when 'FTP_R3_TO_SERVER'
Dear ,
when i used FTP_R3_TO_SERVER to download data in FTP server
i checked in FTP server file is not storing in proper order in FTP server . plz help how to get the file in proper order .it urgent . full points must be given. i given code below .
DATA : BEGIN OF iresult OCCURS 5,
rec(450),
END OF iresult ,
DATA :
dest LIKE rfcdes-rfcdest VALUE 'SAPFTP',
compress TYPE c VALUE 'N',
host(64) TYPE c.
DATA: hdl TYPE i.
DATA: BEGIN OF result OCCURS 0,
line(100) TYPE c,
END OF result.
DATA : key TYPE i VALUE 26101957 ,
dstlen TYPE i,
blob_length TYPE i.
host = p_host .
DESCRIBE FIELD p_password LENGTH dstlen IN CHARACTER MODE.
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD p_password ID 'KEY' FIELD key
ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD p_password
ID 'DSTLEN' FIELD dstlen.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = p_password
host = host
rfc_destination = dest
IMPORTING
handle = hdl
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF sy-subrc = 0.
CONCATENATE 'cd' ftppath INTO ftppath SEPARATED BY space .
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = ftppath
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc = 0 .
CLEAR result .
REFRESH result .
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = 'ascii'
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc = 0 .
DESCRIBE TABLE iresult LINES lines.
blob_length = lines * width .
clear : lines.
Delete the existing file
CONCATENATE 'del' ftpfile INTO delfile SEPARATED BY SPACE.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = delfile
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
*End of deleting the existing file
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = hdl
fname = ftpfile
blob_length = blob_length
TABLES
blob = iresult
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF sy-subrc 0 .
WRITE 'Error in writing file to ftp' .
ELSE.
WRITE 'File downloaded on the ftp server successfully'.
ENDIF.
ENDIF.
ELSE.
WRITE : 'Path on ftp not found : ' , ftppath .
ENDIF.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = hdl.
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = 'SAPFTP'
EXCEPTIONS
OTHERS = 1.
ELSE.
WRITE 'Could not connect to ftp' .
ENDIF.
ENDFORM. " FTPFINANCEACCESS_DOWNLOAD
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'PASSWORD'.
screen-invisible = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
Edited by: manoj kv on Feb 27, 2008 12:55 PM
Edited by: manoj kv on Feb 28, 2008 5:37 AM
Edited by: manoj kv on Feb 28, 2008 5:39 AM
Edited by: manoj kv on Mar 5, 2008 2:15 PM
Edited by: manoj kv on Mar 7, 2008 12:51 PMHello,
Did you try to put 'X' to the parameter CHARACTER_MODE.
Hope it will help you
Olivier -
Hai,
I want to read the files present in FTP server without downloading.
Using (org.apache.commons.net.ftp.*); this package I can view the files and directories present in particular host and can even download.
But I want to read the files in directories without downloading them for displaying the file contents in my JApplet.
How can I achieve this?
Waiting for reply...
Dhuraithis is the wrong forum for such q.
-
Hi Experts,
I need to place the file in "C:/CacheSys/PI" in FTP server.
what is the target directory i must specify in Communication channel.
Kind Regards,
kiranHi
you can use the same name in the target directory.
but the folder that you create should be on the same path.
C:/CacheSys/PI
go to c: dir , then go to Cachesys then go to PI and put the file in this folder.
if you still face the problem please reply me back.
Thanks
Rinku -
Multiple FTP server files for sender File adoptor
Hi,
we have a requirement to pick files from different FTP servers and send it as a proxy message to ECC.File structure format for both FTP server locations is same and I need to send as a same proxy message.
Please let me know how to achieve this. Thanks.
Regards,
RajeshHi Rajesh,
Here you are having two FTP Server to pick the files so that you need to create below list of objects.
For two different FTP Server you need to create two different sender systems
2 sender File channels
2 sender agreements
2 receiver determinations
2 interface determinations(use single inbound interface in both interface determinations)
2 receiver agreement
If you want to use single sender then
2 sender File channels
2 sender agreements
2 receiver determinations
2 interface determinations(use single inbound interface in both interface determinations)
1 receiver agreement
thanks,
madhu -
Reading and transfering FTP server files
Hi Everybody,
I will be really thankful if anybody can guide me for following-
1. How to read/access a file on FTP server ?
2.How file on FTP sever can be downloaded on presentation server?
Thanks.Hi ,
Check Function Group SFTP from se80.
Check this post.
http://wiki.sdn.sap.com/wiki/display/ABAP/WorkingwithFTP+Server -
Hi All,
I have a requirement where I need to delete a file from the FTP server. How do I do that?
Thanks in Advance.
Regards
JaspreetHi,
refer this link,
[ABAP solution to implement FTP transactions |http://wiki.sdn.sap.com/wiki/display/Snippets/ABAPsolutiontoimplementFTP+transactions]
Regards,
Vijay -
No Data in PDF file in FTP server
Hi All,
I am trying to place a PDF file in FTP server.
Used
CONVERT_OTFSPOOLJOB_2_PDF to convert spool to PDF
SCMS_TEXT_TO_XSTRING
FTP_R3_TO_SERVER to transfer data to FTP.
I am able to see PDF file in FTP and no of pages matches with that of R/3 but there is no data in PDF file.To get pdf file , you need to set the itcpo-tdgetotf = 'X' and need to pass in the exporting parameter (options in open_form function module ).Then in close_form function module take all the data of otfdata table into an internal table . Then use SX_OBJECT_CONVERT_OTF_PDF function module to convert it to pdf.
I will show with an example.
tables itcpo.
DATA: ch_otf TYPE STANDARD TABLE OF itcoo.
DATA: w_otf TYPE itcoo.
DATA: w_pdf TYPE solisti1. "For PDF
DATA: i_content_txt TYPE soli_tab.
DATA: temp1 TYPE sx_format VALUE 'OTF',
temp2 TYPE sx_format VALUE 'PDF'.
DATA: c_printer TYPE sx_devtype VALUE 'PRINTER'.
DATA: w_transfer_bin TYPE sx_boolean. "Content
DATA: i_content_bin TYPE solix_tab, "Content
wa_content_bin TYPE solix,
i_objhead TYPE soli_tab.
itcpo-tdnoprint = 'X'.
itcpo-tdpreview = 'X'.
itcpo-tdgetotf = 'X'.
These three parameters need to be passed along with other required parameters
CALL FUNCTION 'OPEN_FORM'
EXPORTING form = xformular
language = ekko-spras
OPTIONS = itcpo
archive_index = toa_dara
archive_params = arc_params
device = xdevice
dialog = xdialog
mail_sender = sender
mail_recipient = recipient
EXCEPTIONS canceled = 01.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT
tables
otfdata = ch_otf.
LOOP AT ch_otf INTO w_otf.
CONCATENATE w_otf-tdprintcom w_otf-tdprintpar
INTO w_pdf.
APPEND w_pdf TO i_content_txt.
ENDLOOP.
converting otf file to pdf file
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = temp1 "'OTF'
format_dst = temp2 "'PDF'
devtype = c_printer
CHANGING
transfer_bin = w_transfer_bin
content_txt = i_content_txt
content_bin = i_content_bin
objhead = i_objhead
len = v_len_in
EXCEPTIONS
err_conv_failed = 1
OTHERS = 2.
Then open dataset and transfer to ftp of the content of table content_bin(i_content_bin) as shown in above example.
I think this will be helpful for you -
How to read the file from ftp server
Hi
I need to read a file from a ftp server . Iam using apache lib common-net .jar .
FTPClient ftp = new FTPClient();
ftp.connect(server);
ftp.login(username,password);
FTPFile[] files = ftp.listFiles();
for(int i=0 ;i<files.length;i++){
System.out.println(" File : "+ i + " - " + files);
InputStream ip = ftp.retrieveFileStream(path);
I got the inputstream from the ftp server. but iam not able to read the contents of the file ....
help me plzzzzzHi
I have one more problem . first i try to read the file and write the file in local directory . then i try to read the data in the remote file .. iam getting the datas as null.
InputStream ip = ftp.retrieveFileStream(path);
File f = new File("D:\\ftp.txt");
FileOutputStream fo = new FileOutputStream(f);
byte[] buf = new byte[1024];
while ((len = ip.read(buf)) > 0) {
fo.write(buf,0,len);
fo.close();
BufferedReader br = new BufferedReader(new InputStreamReader(ip));
String line;
do {
line = br.readLine();
System.out.println(" data " +line);
}while (line != null); -
Problem while reading the file from FTP server
Hi Friends,
I have a problem while fetching files from FTP server.
I used FTP_Connect, FTP_COMMAND function modules. I can able to put the files into FTP server.
but I cant able to pick the files from FTP server.
anyone have faced similar issues kindly let me know.
Thanks
GowrishankarHi,
try this way..
for reading the file using FTP you need to use different unix command ..
Prabhuda -
How to read .xls file from FTP server t oInternal table
Hi
am using the FTP_SERVER_TO_R3 to read xls file from FTP server to internal table
but the data i get in LT_TEXT is special characters.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = hdl
fname = f_name "ProdDataFromCRM.xls.
* CHARACTER_MODE = 'X'
* IMPORTING
* BLOB_LENGTH =
TABLES
BLOB = lt_text
* TEXT = lt_text
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4
can any one help me out to get the exact data..
Really appreciate your quick response..
Thank YouHi, if you really retrieve an excel file, you can not see the data in ABAP. You may see them in Excel. For this you may use
CALL METHOD document->open_document_from_table
of the interface i_oi_document_proxy for OLE objects. You can access the data with reference to the interface i_oi_spreadsheet.
Please check [Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf] for details.
But, who knows, perhaps you want "And Now For Something Completely Different".
Regards
Clemens -
Need to copy .txt file from FTP server and downloaded on local server directory.
I need to figure out a way to copy .txt file from ftp server in local server directory using sql jobs.
Below links will help achieving it:
https://www.virtualobjectives.com.au/sqlserver/ftp_scripts.htm
http://www.mssqltips.com/sqlservertip/2884/sql-server-integration-services-ssis-ftp-task-for-data-exchange/ -
How to read XL file from FTP server
Hi all,
I have a requirement like to read file from FTP server using path
ftp:
10.212......\DTR\DTR_ Accounted_Out
and again save other file in same location ,
to doing this RFC connection is required?
give a procedure or program to do this requirement ..
To create rfc for FTP which connection type can i use ?
Give complete settings to create rfc destinationHi Rakhi,
Use the below code to check if you have received the proper data.
call function 'FTP_SERVER_TO_R3' "Get data as character instead of BLOB
exporting
handle = hdl
fname = docid
character_mode = 'X'
tables
text = chardata.
If the data is incorrect, it is possible that you are in the wrong directory.
Use
call function 'FTP_COMMAND'
exporting
handle = hdl
command = 'cd mydir\mysubdir' "cd <space> your path
tables
data = result
exceptions
tcpip_error = 1
command_error = 2
data_error = 3.
Regards,
Jovito. -
Problem with downloading file from FTP server
Hello all
I have uploaded a file from an application i developed and i want to download this file from another application. The code is
public static void FTPcon() throws FtpException{
String hostname = "my.ftp.server";
String username = "myusername";
String password = "mypass";
Ftp ftp = new Ftp(hostname,username,password);
ftp.setHostname(hostname);
ftp.setUsername(username);
ftp.setPassword(password);
ftp.connect();
ftp.setBinary();
ftp.download("file.dat");
ftp.disconnect();
}The error i receive is java.io.FileNotFoundException: public.dat (The system cannot find the file specified) but the file is on the server.
Thanks in advance for any helpCotton thank you for your reply
Any other sugestions please?The server disagrees. So...
- the file does not existThe file exists.I checked it with an FTP client program.
- the file has a different nameThe file name is correct
- you are connected to the wrong serverI am connecting to the correct server
- you are in the wrong ftp directoryThe file is placed in the home directory
- the ftp library you are using is broken (less
likely)I am using the library from jscape.I dont think is broken because i can upload the file from the first application.
>
FTP isn't somehow broken in Java. I use it all the
time. The problem is something listed above. I would
check all of the first four if I were you because
that's most likely where the problem is.Message was edited by:
flightcaptain -
Problem in Archiving File From FTP Server to XI File Server Using FCC
Hi,
The scenario is file to IDOc. XI has to read the input file from client FTP server and archive it to XI local file server. Archiving on XI server is working fine without FCC (for xml files). But with FCC, the sender FTP adapter is archiving empty files (0 kb files).
I've checked SXMB_MONI, even there I can see the file data and the IDoc is getting posted with proper data. But, the archived file is empty. Not sure about the problem.
Please suggest. Thanks in advance.
Regards,
Joe.Hi,
File adapter has the functionality which support the empty file handling.
Handling of Empty Files
Specify how empty files (length 0 bytes) are to be handled.
○ Do Not Create Message
No XI messages are created from empty files.
The files are processed according to the selected Processing Mode.
For example, if the processing mode is Delete, empty files are deleted in the source directory.
○ Process Empty Files
XI messages are created with an empty main payload.
The files are processed according to the selected Processing Mode.
○ Skip Empty Files
No XI messages are created from empty files.
Empty files are skipped and remain in the source directory.
refer the belwo link:
http://help.sap.com/saphelp_nw04/helpdata/en/ae/d03341771b4c0de10000000a1550b0/frameset.htm
reward points if helpful*
thanks
SAPXI
Maybe you are looking for
-
Importing Microsoft Word document with images to InDesign CS5
Hey, I'm trying to import a MS Word document that contains inline images to InDesign CS5. I tried File->Place with checking "Import Inline Graphics" but unfortunately it imports the document without the images, there are blank regions where the image
-
Error -8 - how to track the problem?
Hi, Any/all help appreciated: I was able to v/c with my father in the UK (PC user) via AIM until recently - now getting error -8. - I can chat with the Apple testbots (appleu3test01 et al) fine. - I am using Comcast modem with linksys router. Removin
-
Clarification on Adobe Document Service credentials
Hello, I want to use Adobe Document service for printing of a non interactive document in a custom built webdynpro application. If i interpret the following threads on licenses of Adobe Document service in this forum correctly, my requirement does no
-
Every 10 seconds i get this error ""NoClassDefFoundError""
####<Aug 23, 2012 8:40:45 AM CEST> <Error> <Kernel> <pl-1> <traffic-1> <[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1345704045182> <BEA-000802> <ExecuteRequest failed java.lang.NoClassDefFoun
-
Primavera P6 timesheet installation errors
Dear all, thanks a lot for you help, if you could answer my question in the process of installing Primavera timesheet GS_inst.exe. before the timesheet installation finish, it appears a error message: "An unhandled win32 exception occurred in GS_Inst