HOW to read file using ftp???

Hi to all,
I have problem with reading file using ftp connection, i want to read only 1024 bytes for one time, and i have
next code wich read this:
byte buffer[] = new byte[1024];
while( (readCount = input.read(buffer)) > 0) {
bos.write(buffer, 0, readCount);
but I dont know how to put all read data in one byte[] if i dont know length of file.
I can't do some like: byte file[] = new file[1000000];
Thanks for all sugestions!

      * Download a file from a FTP server. A FTP URL is generated with the following syntax:
     * <code>ftp://user:password@host:port/filePath;type=i</code>.
      * @param ftpServer FTP server address (incl. optional port ':portNumber').
      * @param user Optional user name to login.
      * @param pwd Optional password for <i>user</i>.
      * @param fileName Name of file to download (with optional preceeding relative path, e.g. one/two/three.txt).
      * @param destination Destination file to save.
     * @throws MalformedURLException, IOException on error.
     public void download(String ftpServer, String user, String pwd, String fileName, File destination) throws MalformedURLException, IOException {
        if (ftpServer != null && fileName != null && destination != null) {
            StringBuffer sb = new StringBuffer("ftp://");
            if (user != null && pwd != null) { //need authentication?
                sb.append(user);
                sb.append(':');
                sb.append(pwd);
                sb.append('@');
            }//else: anonymous access
            sb.append(ftpServer);
            sb.append('/');
            sb.append(fileName);
            sb.append(";type=i"); //a=ASCII mode, i=image (binary) mode, d= file directory listing
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                URL url = new URL(sb.toString());
                URLConnection urlc = url.openConnection();
                bis = new BufferedInputStream(urlc.getInputStream());
                bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
                int i;
                while ((i = bis.read()) != -1) { //read next byte until end of stream
                    bos.write(i);
                }//next byte
            } finally {
                if (bis != null) try { bis.close(); } catch (IOException ioe) { /* ignore*/ }
                if (bos != null) try { bos.close(); } catch (IOException ioe) { /* ignore*/ }
        }//else: input unavailable
    }//download()If you don't want to strore the data into a file, use ByteArrayOutputStream instead of a FileOutputStream.

Similar Messages

  • How to download file using ftp in bash script

    Hi! I'm runnig a bash script in solaris i want within the script to dowload file using ftp
    How can i do it?
    Tanks a lot

    hello,evgchech
    please try this way:
    1. In the bash script, try following command:
    ftp -n < ftpcmdfile2 in the ftpcmdfile (which is a file),coding the interactive commands of FTP such as:
    user anonymous  [email protected]
              cd /var/sun/download
              bi
              mget *.*
              bye
         try it and good luck!
    Wang Yu
    Developer Technical Support
    Sun Microsystems
    http://sun.com/developers/support

  • How to transfer file using FTP

    Hi All
    I want to transfer few files from one instrument running WIndows Xp to another PC running on Windows Xp.
    I do have installer LabVIEW 8.2 & also Internet Toolkit on the PC.
    Now do i need to install anything on instrument also from where i need to transfer the files.
    Thanks & Regards,
    Rajan
    Thanks & Regards,
    Rajan

    duplicate post

  • Oracle read files from FTP Server

    Hi,
    Somebody knowns Oracle how to read files from FTP Server ? Which package I can use?

    Duplicate post
    Oracle read files from FTP Server

  • How to Create a Flat File using FTP/File Adapter

    Can any body done workaround on creating the Flat file using FTP/File Adapter?.
    I need to create a simple FlatFile either using of delimiter/Fixed length. using the above said adapters we can create XML file, i tried concatinating all the values into a single String and writing into a file, but it does not have proper structure
    Can any body help me out on this..
    Thanks
    Ram

    You can create a text schema while creating a File Adapter. If schema is specified for File Adapter, it takes care of converting XML into fixed length or delimited format.
    Thanks,
    -Ng.

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to upload a file using FTP tin JSP

    Hello friends ,
    I m actually looking to upload a file using FTP to a server(webserver) in JSP . If there any tags available to accomplish this r any information regading this plzz let me no.
    Thanks in advance
    P.Satish

    Not sure exactly what you're trying to do but you set the content type a stream it to the browser from a servlet

  • How to delete file on ftp server

    hello,how to delete file on ftp server?thank you!

    I was trying to hint to the fact that you gave no where near enough information.
    Have you already written anything? Such as software that will connect to an FTP server?
    Are you using a 3rd party package?
    Are you doing it by hand, using sockets?

  • [Urgent] How to read files from different directories?

    I am new to Java Programming, I would like to know how to read files from directories other than the current one? (example as follows)
    ProjectDirectory
    |--MainDirectory
    |--MainProgram.java
    |--SupplementDirectory
    |--SupplementProgram.java
    |--Pictures
    |--Image.gif
    What should I write in the MainProgram.java so that I can use the supplementProgram.java from MainProgram and read the Image.gif file from the MainProgram.java?
    Thanks

    Run through the I/O tutorial here. It should get you up to speed on this sort of thing...

  • How to read files....plzzz

    Hi! All,
    I have a problem in reading files using jfilechooser class.
    when i select open menuitem from the file menu and reading it through
    the file reader class it is giving nullpointer exception.
    Also i tried by hardcoding filename in filereader class instead of using getSelectedfile().This time it is not giving null pointer exception but it is showing any stuff.
    Here's the code i am using...
    int returnVal = fc.showOpenDialog(openpanel);
    if(returnVal == JFileChooser.APPROVE_OPTION){
    file = fc.getSelectedFile();
                   //This is where a real application would open the file.
    if(fc == null)
         file = new File("D:\\karthik\\java\\");
         file = new File("D:\\karthik\\java\\kar.txt");
         fc.setCurrentDirectory(file);
    BufferedReader infile = new BufferedReader(new FileReader(file));
         files.append(infile.readline()); //files is the textarea..

    how come you do a fc.setCurrentDirectory(file);?
    where exactly do you get the NullPointerException? what does your stacktrace say?
    thomas

  • Reading file using File Adapter in BPEL

    Hi,
    I am using JDeveloper 11g.
    I am trying to Read XML file and write content to Text file.
    I created XML Schema, XML file.
    I created Asynchronous BPEL process (Auto Generated)
    I took one File adapter which will have Read operation and one more File Adapter which will have Write Operation.
    Then, added one Receive activity that will be connecting to partner link - Read.
    and one Invoke activity which is linked to Write Partner link .
    I am able to Deploy the process..
    While testing 1st receive (Auto generated) will work but Receive for Read is not getting started.
    I am getting " Waiting for "Read" from "ReadFile". Asynchronous callback.Waiting for "Read" from "ReadFile". Asynchronous callback "
    How to read file in BPEL process. ?
    Thanks

    So,You have two receive activity(One for soap client and one for Read activity) and two invoke(1 for write file and 1 for reply to client).
    I think the 1st receive activity for soap client not required as you want to initiate the process while read the file.You can delete the default soap client and corresponding receive activity and check the create instance chekbox in the 2nd receive activity linked with read partnerlink.
    There is some issue with 2nd receive activity in bpel ..
    BPEL 11g -- Issue with second Receive activity
    Edited by: blue bell on 10-Sep-2011 22:33

  • Reading file from FTPs

    I have to read from different locations(FTP Servers) if there are any new files I have to transform those to my ftp, If I place a new file in my ftp it has to go to the other ftps.
    Can i achieve this with a single ESB service?
    I believe I can do it using two ESB services.
    Can I read .xls files using FTP adapter and transform them to XML??
    Any suggestions please, it is very urgent
    Thanks
    V Kumar

    Define an ESB service that:
    - read file with FTP adapter in ESB
    - From your services it writes the file to the other FTP location.
    Create the services for all ftp location to want to touch.
    Marc

  • How to call serlvet using ftp protocal

    Hai,
    How to call servlet using ftp protocal . if any one having please send that program . because generic servlet will receive any protocal request .

    The basics are to have your Server listen to port 21.
    You would then have to parse the request information to determine what is being asked for and generate an appropriate response.

  • Dowload file using ftp in bash script

    Hi! I'm runnig a bash script in solaris i want within the script to dowload file using ftp
    How can i do it?
    Tanks a lot

    hello,evgchech
    please try this way:
    1. In the bash script, try following command:
    ftp -n < ftpcmdfile2 in the ftpcmdfile (which is a file),coding the interactive commands of FTP such as:
    user anonymous  [email protected]
              cd /var/sun/download
              bi
              mget *.*
              bye
         try it and good luck!
    Wang Yu
    Developer Technical Support
    Sun Microsystems
    http://sun.com/developers/support

  • Not able to send file Using FTP in SSIS 2005

    I am using SSIS 2005
    I am trying to send file to ftp server using FTP task in SSIS but i am getting following error.
    Error Message-:An error occurred in the requested FTP operation.
    Detailed Description-:550 /FileName.txt: Access is denied.
    RemotefilePath is /
    I need a advice.
    Thanks in advance.

    I got this error recently from the FTP task in SSIS:
         Unable to send files using "FTP".
    I had everything correct, by the book.  I was trying to send a file, but I got the same error when trying to receive a file. 
    I already verified that I could send the file via command line FTP, so the FTP was not "secure FTP" (which wouldda required FileZilla or WinSCP or something similar) and my credentials were fine. 
    But I still got the above error.  Heck, I was beginning to thing that the FTP task in SQL Server 2008 was broken and just couldn't send files.
    Well, this issue is now resolved.  The problem was in the
    destination folder.  I was assuming that the root folder for my FTP account held the files. 
    So I entered the destination folder as this:   
    /data_in/
    But... the FTP task sees the root folder as one up from that. 
    So I had to use my account name in the path... meaning I had to change the destination folder to this:    
        /myaccountname/data_in/
        (where "myaccountname" was my login to the FTP site.)
    I hope this post helps someone else.
    Donna

Maybe you are looking for