Java code to create a new .txt file in FTP server  --- Help

Hi,
I wrote a standalone java app which creates a .txt file in my local machine and transfers it to FTP server. But my requirement now is to create a new .txt file with the same content in FTP server itself instead of creating locally with basic java code.
I'm aware of transfering file from local machine to the FTP server using STOR command of FTP. But i never tried creating a new file & writing content into that in FTP server.
So, if any one did this before please help me out with source code or any idea ???
Thank you.
Vj.

simply_vijay wrote:
thanks for your reply. yes i've seen the Apache Commons NET API , but there is no method or class to create a new file in FTP server. I'm really worried how to solve this problem ???Sure there is.
There's a method where you can write data to a file on the server using an OutputStream, right? Well, instead of writing to a FileOutputStream, write to that OutputStream instead. Remember to close the OutputStream and call the method which says you're finished with the command (I forget what it's called).

Similar Messages

  • 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 create a new txt file on the hard disk?

    Which method in which class should I use?

    there are documantatiosn and tutorials :
    createNewFile :
    "Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. This method, in combination with the deleteOnExit() method, can therefore serve as the basis for a simple but reliable cooperative file-locking protocol.
    Returns:
    true if the named file does not exist and was successfully created; false if the named file already exists"

  • Garbage when create a new txt file

    I'm creating a text file but when a check the file it contain
    some garbage...
    salida = new DataOutputStream (new FileOutputStream ("client.txt"));      
    salida.writeUTF("Hello");
    salida.writeUTF("my");
    salida.writeUTF("world");
    but when i check the file it contain:
    Hello my wold
    i don't know why appear this caracter
         

    This behaviour is normal, the fact that you are using DataOutputStream to write the data to the file means that you want the Java Primitive datatypes to be written in the file for reading the way they are in future.
    If you use DataInputStream rather than notepad to read this data you will find that the data is fine.
    If you want to make a file human readable and are going to write text to it, might as well use the FileOutputStream.
    Cheers.

  • [HELP] Download file from FTP server

    hi,
    I want to write a java program that can download and upload files from ftp server. Currently I only manage to upload a file to ftp server but i cant download file from ftp server. Here is the source code that only allow user to upload file. Anyone can give me some guidelines so that my program can download and also upload file? thx.
    import java.io.*;
    import java.net.*;
    public class FTPUpload {
    private static final int CTRLPORT = 21;
    private static Socket ctrlSocket;
    private static PrintWriter ctrlOutput;
    private static BufferedReader ctrlInput;
    private static byte[] localHostAddress;
    public final static String DIR = "C:\\zip\\";
    public static void main(String[] args) {
    try {
    String host = "192.168.1.1";
    String loginName = "testuser";
    String password = "password";
    String dirName = "/home/testuser";
    String fileName = "hello.zip";
    ctrlSocket = new Socket(host, CTRLPORT);
    localHostAddress = ctrlSocket.getLocalAddress().getAddress();
    ctrlOutput = new PrintWriter(ctrlSocket.getOutputStream());
    ctrlInput = new BufferedReader(new InputStreamReader(ctrlSocket.getInputStream()));
    ctrlOutput.println("USER " + loginName);
    ctrlOutput.flush();
    ctrlOutput.println("PASS " + password);
    ctrlOutput.flush();
    ctrlOutput.println("CWD " + dirName);
    ctrlOutput.flush();
    ctrlOutput.println("TYPE I");
    ctrlOutput.flush();
    FileInputStream fis = new FileInputStream(DIR + fileName);
    Socket dataSocket = dataConnection("STOR " + fileName);
    OutputStream outstr = dataSocket.getOutputStream();
    int n;
    byte[] buff = new byte[1024];
    while ((n = fis.read(buff)) > 0) {
    outstr.write(buff,0,n);
    dataSocket.close();
    fis.close();
    ctrlOutput.close();
    ctrlInput.close();
    ctrlSocket.close();
    }catch (Exception e) {
    e.printStackTrace();
    private static Socket dataConnection(String ctrlcmd)
    throws IOException,UnknownHostException {
    String cmd = "PORT ";
    ServerSocket serverDataSocket = new ServerSocket(0,1);
    for (int i=0;i<4;i++) {
    cmd = cmd + (localHostAddress[i] & 0xff) + ",";
    cmd = cmd + (((serverDataSocket.getLocalPort())/256) & 0xff)
    + ","
    + (serverDataSocket.getLocalPort() & 0xff);
    ctrlOutput.println(cmd);
    ctrlOutput.flush();
    ctrlOutput.println(ctrlcmd);
    ctrlOutput.flush();
    Socket dataSocket = serverDataSocket.accept();
    serverDataSocket.close();
    return dataSocket;
    }

    Or just use a java.net.URL("ftp://...) ..., get its input stream, and away you go ...

  • How to download  n  files  to FTP server in background using single report?

    Hi all,
    I have one requriement where i have to download 7 different text ( *.txt ) files to FTP server weekly using single program in background mode.
    I have populated all the 7 internal tables with their corresponding data.  But i dont know how to proceed further.
    Please help me out .....
    Thanks in advance..

    hi,
    U can store the Internal table name and File name in an internal table.
    Then loop at that table and call function called 'GUI_DOWNLOAD' inside that loop.
    Rgds,
    Sanjeet

  • How to write a code for  open new txt file in swing

    hai all,
    now i do one project in java.that project's GUI is Swing. But i don't known swing (basic).So how to write a code for open new txt file and "Open window " in menu item on swing.that means when i click the "New" on menu that time open a new txt file. open also like that type.
    plz give me that code ! very urgent
    Advance Thanks !
    RSK

    Swing Tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    Since you don't know the basic of swing read the tutorial, it is for your own good because it is useless if we provide you with a code you don't even understand and how it works.
    If you want a menu read the tutorial about using menus and for opening a file read using JFileChooser.
    note: don't use the word urgent because it implies that your problem is more important than others.

  • When we click turminate button in eclipse new txt file has to be created ?

    when we click turminate button in eclipse new ,txt file has to be created ?
    how can we do this............??

    abenstex wrote:
    That really would be a pity, because the final answer might be interesting...;-)Pending a definition of "turminate button", it wouldn't be too difficult to generate a new txt file on pressing it. No idea why you'd want to, though

  • JAVA CODE  NOT CREATING IDOC

    Hi all
    I m facing problem to upload data through idoc.the scenario is like we receive electric meter reading in flat file format. And to upload that data JAVA code is written which will create an IDOC FILE this authorization is only give to 2-3 person in organization and to basis guy also as user changed it’s password in SAP and in JAVA the java code is not going to create the IDOC file and data is not going to upload. after changing user password in sap system ,user not able to upload the data.
    ISU_MR_UPLOAD01 is the idoc file generated. So is there any authorization issue, password issue how to see and view IDOC IN SAP, can any one help me out into this.
    The error with java throws is as;
    1ST ERROR IN TRACE FILE
    ERROR file opened at 20061109 133610 India Standard, SAP-REL 640,0,59 RFC-VER 3  MT-SL
    T:2736 ======> User TR has no RFC authorization for function group SYST .
    T:2736 <* RfcReceive [1] : returns 3:RFC_SYS_EXCEPTION
    2ND ERROR ON COMMAND PROMT
    C:\j2sdk1.4.2_07>cd bin
    C:\j2sdk1.4.2_07\bin>java sandsupload
    Creating IDoc...Exception in thread "main" com.sap.mw.idoc.IDoc$Exception: (2) I
    DOC_ERROR_METADATA_UNAVAILABLE: The meta data for the IDoc type "ISU_MR_UPLOAD01
    " is unavailable.
            at com.sap.mw.idoc.jco.JCoIDoc$JCoDocument.<init>(JCoIDoc.java:233)
            at com.sap.mw.idoc.jco.JCoIDoc$JCoDocument.<init>(JCoIDoc.java:187)
            at com.sap.mw.idoc.jco.JCoIDoc.createDocument(JCoIDoc.java:10521)
            at sandsupload.main(sandsupload.java:35)
    the part of java code
    try {
                //create a JCo client pool
                JCO.addClientPool( "MyPool",    //pool name
                                   3,           //maximum pool connections
                                   "333",       //SAP client
                                   " TR",    //user ID
                                   " XYZ",  //password
                                   "EN",        //language
                                   " 1.1.1.1   ", //app server host name
                                   "00" );   //system number
                //create an IDoc repository
                IDoc.Repository idocRep = JCoIDoc.createRepository("MyIDocRepository", "MyPool");
                //create a new and empty MATMAS02 document
                System.out.print("Creating IDoc...");
         Line where it shows error
                IDoc.Document doc = JCoIDoc.createDocument(idocRep, "ISU_MR_UPLOAD01");
                //get the root segment from the document
                //The root segment does not contain any fields or data. It is only
                //used as the standard parent segment and won't be transmitted when
                //the document is sent to an SAP system.
                IDoc.Segment segment = doc.getRootSegment();
                //create and add a new and empty child segment of type E1MARAM
                //and fill the segment data

    Hi Gaurav,
    Same exception on the same line has been reported and marked as solved here :
    IDOC_ERROR_METADATA_UNAVAILABLE:
    Btw, I think this forum is not visited often by JCO and ABAP connectivity experts, so maybe you could get a faster response to your problems while posting in "Java Programming" or maybe in some forum under the category ABAP Development.
    HTH
    Peter

  • Help with creating a new XML file from an existing DOM tree!!

    i want to create a new XML file from an existing DOM tree
    i used this code to create a new document:
    static public Document createDocument(String fileName) throws ParserConfigurationException//,IOException,SAXException
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setIgnoringComments(true);
                   factory.setIgnoringElementContentWhitespace(true);
                   factory.setValidating(true);
                   DocumentBuilder builder =factory.newDocumentBuilder();
                   return builder.newDocument();
    //          handle exception creating DocumentBuilder
              catch ( ParserConfigurationException parserError ) {
                        throw new ParserConfigurationException();
              }then i used this code to transform the DOM :
    public void exportDocument(Document document) {
              try {
                   Source xmlSource = new DOMSource( document );
                   Result result = new StreamResult( System.out );
                   TransformerFactory transformerFactory =
                        TransformerFactory.newInstance();
                   Transformer transformer =transformerFactory.newTransformer();
                   transformer.setOutputProperty( "indent", "yes" );
                   transformer.transform( xmlSource, result );
           //then catching the exceptions
    But the file was not created and i didn't find where can i specify the DTD that the XML file should use and where can i enter the name of the XML file itself
    Another questoin can i write a DTD file dynamically during the execution of the program??

    Cross-post: http://forum.java.sun.com/thread.jspa?threadID=784467&messageID=4459240#4459240

  • Create a new HTML file by changing attributes

    Hello, I am going to add some attributes to create a new html file.
    Such as
    <div id="globalWrapper">becomes
    <div id="globalWrapper" style=...>I have completed partial task, but I have trouble on how to save it to a new file.
    Please look at my code.
    import java.awt.Point;
    import java.io.*;
    import java.util.*;
    import javax.swing.text.EditorKit;
    import javax.swing.text.MutableAttributeSet;
    import javax.swing.text.html.HTML;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.HTMLEditorKit.InsertHTMLTextAction;
    import javax.swing.text.html.parser.ParserDelegator;
    public class ReadTest extends HTMLEditorKit.ParserCallback
         public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos){
             if     (
                         (t == HTML.Tag.BR)   ||
                         (t == HTML.Tag.DIV)  ||
                         (t == HTML.Tag.P)    ||
                         (t == HTML.Tag.UL)   ||
                         (t == HTML.Tag.UL)   ||
                         (t == HTML.Tag.DD)   ||
                         (t == HTML.Tag.BR)   ||
                         (t == HTML.Tag.H1)   ||
                         (t == HTML.Tag.H2)   ||
                         (t == HTML.Tag.H3)   ||
                         (t == HTML.Tag.H4)   ||
                         (t == HTML.Tag.H5)   ||
                         (t == HTML.Tag.H6)  
             a.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,"style=");// right or wrong? Then what?
             System.out.println(a);
        public static void main(String argv[]) {
        try {
            Reader r = new FileReader("C:/test.html");
            ParserDelegator parser = new ParserDelegator();
            HTMLEditorKit.ParserCallback callback = new ReadTest();
            parser.parse(r, callback, true);
            EditorKit kit=new HTMLEditorKit();                       
            HTMLDocument doc=(HTMLDocument)kit.createDefaultDocument();  
      } catch (IOException e) {
            e.printStackTrace();
    }Thanks

    The first two concerns are the source footage and then the Project/Sequence Preset.
    What are these? This answer will direct others on how they suggest that you proceed.
    For OOS issues, having your source footage in the proper format will go a long way to solving such issues. For "fixing" OOS, this ARTICLE might be useful.
    Good luck,
    Hunt

  • How to create a New Excel File programmatically

    Hi !
    I am documenting acquired data continuously in an excel file, what I need to do is to create a new excel file automatically when the size of the previous file exceeds a certain limit lets say 1MB.
    I have tried using the simple 'Create/Open File' function and the 'Write to Spreadsheet File' function to create the new excel file. I does create a file but when I open the file it says the format of the file is not what you have opened it with.
    Also when the new file is created, three new worksheet are to be added programmatically with pre-defined worksheet name and also Column headers for each of the worksheet are to be added.
    I am also using 'Labview Report Generation Toolkit for Office'.
    Regards,
    Reeves
    Solved!
    Go to Solution.

    @ Aldo A
    Thanks for the reference to tutorial, I didn't know about them. They are useful in general but unfortunately they don't answer the problem of creating an altogether new excel file programmatically.
    @ ben64
    The template thing simplifies the issue of formatting the new file. But I am still working on the new excel file creation challenge.
    Let me put my problem in a different way.
    Certain data is being acquired continually and is being written to a certain excel file, when the size of the file exceeds lets say 1MB the program should start saving the data in a NEW FILE instead of the previous file.
    I have attached the VI to explain what I am trying to achieve here.
    Reeves
    Attachments:
    New Microsoft Office Excel Worksheet.zip ‏30 KB

  • When I open iTunes, I get a message that "iTunes has stopped working".  I've tried reinstalling itunes, creating a new user file, changing the startup programs, and am having no success in getting iTunes to stay open. Any "fixes" for this problem?

    When I open ITunes, I get a message that "iTunes has stopped working".  I have tried reinstalling iTunes, creating a new user file, changing the startup programs in accordance with articles in iTunes troubleshooting, but am having no success in getting iTunes to stay open.  Any fixes for this problem?

     

  • Is it possible to open a new Worksheet without creating a new *.sql file

    Hello Community,
    Declaimer: It may be a trivial question. I just willing to make SQL Developer my default day to day tool.
    I is possible to open a new Worksheet without creating a new *.sql file. Like in an MS Word. If I just need some space to write something and than destroy the file without saying. I can quickly click < ctrl + N > and get the space.
    In SQL Developer to get a new "space"/work sheet i
    -a- < ctrl + N >
    -b- choose "SQL File"
    -c- confirm default location
    -d- choose the connection to be used (right top conner)
    This process is way to long for getting a new sheet to put write an SQL.
    Can you suggest a better way to get a workspace with current connection assigned in no time (like in MS Word)?
    Please ;)
    Yury

    There is no need to create new .sql file.
    I don't know why you need new SQL Worksheet when you can simply do the space by pressing Enter, but you can open a new one from Tools -> SQL Worksheet. There is also a toolbar button for this.

  • Create a new trace-file

    hello together,
    i have a question according to creation of new user trace files in user_dump_dest:
    with the following command:
    EXEC dbms_system.set_sql_trace_in_session(18,628,TRUE);
    I created a new file in the trace directory.
    Then I stopped the tracing with:
    EXEC dbms_system.set_sql_trace_in_session(18,628,FALSE);
    I disconnected with the traced session sid=18 and connected once again.
    With retracing the session I didn't get a new trace file but the existing trace file was actualized.
    => what do I have to do to achive a new trace file for the second session-tracing?
    Thanks and Regards
    Stefan

    Hello Maran,
    I only want to trace one session; but I want to create a new trace file for the second run when tracing; but at the moment the first trace file will be continued...
    thanks

Maybe you are looking for