Read file from URL and save to FTP

Hi,
I have worked in java few years back, now I am out of touch. My friend asked me to create an applet program for him which he can use to download a file from remote location to his ftp server.
For e.g.
File
http://www.demo.com/filename.avi
Saved to
ftp://username:password@ftpsite_address/foldername
I was searching for the classes which I can use to achieve this functionality.
To save to FTP
URL url = new URL("ftp://username:[email protected]/folder/filename");
URLConnection urlconnection = url.openConnection();
long l = urlconnection.getContentLength();
OutputStream outputstream = null;
outputstream = urlconnection.getOutputStream();Using the above code I can get the outputstream to which I can write.
I am now stuck here, have some doubts.
What all classes should I use to read a file like
http://www.demo.com/filename.avi
I know I can use URL to open connection to URLS and then streams to read the url.
I am interested in knowing the class which I should use to read any type of file. File can be zip/avi/rar or anything else.
What all method of the class should I use to read the file which will support all type of files.
Which classes should I use to write the files. The files are going to be huge in terms of size.
I have searched everywhere but every place different classes are used.
Any help is appreciated.

Ok now I have started coding but facing a problem.
[PHP]try {
     URL url = new URL("http://url_to_file/test.txt");
     URLConnection urlconnection = url.openConnection();
     long l = urlconnection.getContentLength();
     fTextArea.append("Content Length = " + l);
     BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
     String line;
     while ((line = in.readLine()) != null)
          fTextArea.append("\n"+line);
     in.close();
} catch (Exception e) {
fTextArea.append(e);
return;
[PHP]
When I run this code locally it works fine but when run in browser it shows security exception
java.security.AccessControlException: access denied (java.net.SocketPermission site:80 connect,resolve)
What should I do to resolve this error. Sorry for being such a noob but do not have much info about this.

Similar Messages

  • Can not read file from URL

    I have this code for loadbitmap() function:
    String s = getCodeBase()+sdir+sfile;
    System.out.println("codeBase is=" + s);
    URL url = new URL(s);
    InputStream fs = url.openStream();
    BufferedInputStream bs = new BufferedInputStream(fs);
    And the file is a .bmp file, so I go on decoding this etc. It works fine within VisualCafe.
    When I created a virtual directory in IIS and run this applet from
    http://localhost/ImageApplet/ImageApplet.html address:
    I get in 1.3.1 Plug-in this error:
    codeBase is=http://localhost/ImageApplet/duke/some1.BMP
    Caught exception in loadbitmap!java.io.FileNotFoundException: http://localhost/ImageApplet/duke/some1.BMP
    If a type this as address in browser, it shows the image.
    Could any one tell me what I am doing wrong here?

    You can try this, even though it is not supposed to be different from your original code:
    URL url = new URL(getCodeBase(), sdir+sfile);
    System.out.println("getting image from " + url);
    InputStream fs = url.openStream();
    BufferedInputStream bs = new BufferedInputStream(fs);
    I could understand a SecurityException but a FileNotFoundException... A FileNotFoundException... You are reading from a stream originating from a URL, not a file!!!
    Which line causes the exception?

  • How can I read file from filepath and Insert in to SQL Server ?

    Hi,
    I have table called "table1" and has data like this ..
    id
    Folder
    FileName
    1
       f:\cfs\O\
    ENDTINS5090.tif

    D:\Grant\
    CLMDOC.doc
    3
     f:\cfs\Team\
    CORRES_3526.msg
    4
      f:\cfs\S\
    OTH_001.PDF
    I have another table called "table2" with content column is image datatype.
    Id
    FileName
    Content
    1
    FileName
    2
    ENDTINS5090.tif
    3
    CLMDOC.doc
    4
    CORRES_3526.msg
    5
    OTH_001.PDF
    I would like to insert in to content column in the table2 by reading the file from filepath( table1).
    Is there any simple way or SSIS  able to do it ?
    Please help me on this.
    Thank you.

    http://dimantdatabasesolutions.blogspot.co.il/2009/05/how-to-uploadmodify-more-than-one-blob.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How can I save adobe reader file from gmail into my adobe reader app?? i would like to open one file in place where I'm not able to access internet and for that reason i would like to save it. is that even possible?

    How can i save adobe reader file from my gmail into my adobe reader application. or is there any other way i can save it into my phone so I'm able to open in any situation not just from my gmail???

    Long hold on the document in mail and it should give you the open in... option, select adobe reader and the file is now saved locally for viewing even while offline.

  • Failed to read wsdl file from url

    Hi all,
    I am struggling with WL 9.2, consuming a WSRP enabled portlet at the following point:
    Having created a proxy portlet, refering to the WSDL of the WSRP producer, I did successfully deploy the portal. When accessing the portal and consuming the portlet the following exception is thrown:
    com.bea.wsrp.faults.TransportException: Failed to read wsdl file from url due to -- java.net.ConnectException: Tried all: '8' addresses, but could not connect over HTTP to server: 'www.w3.org', port: '80';
    The WSDL includes a schema (http://www.w3.org/2001/XMLSchema). The URL is definetely accessible by the server.
    I am open for any kind of support ;) Thanks in advance!
    Kind regards,
    Matthias

    Yes, they are all local schemas. The way ALSB works, even if the import path in the wsdl or parent schema doesn't exist, relative to the current directory, you can specify which schema resolves that reference. My WSDL imports several schemas, all of which import others. When I was done importing all the schemas and resolving references, all the references in WSDLs and XSDs were assigned and valid. However, after all of those imports and reference resolution, it still says the WSDL is invalid, with the following odd error message:
    The WSDL is not semantically valid: Failed to read wsdl file from url due to -- java.net.MalformedURLException: no protocol: /XMLSchema/PaymentServices/Resources/PaymentServices-200802.
    That path listed refers to one of the schemas imported by the WSDL. The reference to that schema in the WSDL was resolved, and it doesn't complain about that reference.

  • Reading Files from an FTP location based on Timestamp

    Hi,
    I have a requirement of reading files from an FTP location. The files should be read in the order they were saved in the folder. Can someone tell me how to solve this?
    Thanks,
    Ravi

    Hi Arik,
    Thanks for your reply. I tried doing what u said, but it isn't working. My requirement is to List the files in the folder using FTP adapter and get the file name with the least file stamp from the FTP adapter and pass the FileName dynamically to another FTP adapter which reads the file based on the FileName. When i tested after including the property (for listing the files) you mentioned, it is giving the following error (copied from flow trace):
    <messages>
    <input>
    <Invoke_getFileListFTP_FileListing_InputVariable>
    <part name="Empty" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <empty xmlns="http://xmlns.oracle.com/pcbpel/adapter/ftp/APP_SequentialFileTransfer/PRJ_SequentialFileTransfer/WS_GetFileList_FTP"/>
    </part>
    </Invoke_getFileListFTP_FileListing_InputVariable>
    </input>
    <fault>
    <bpelFault>
    <faultType>0</faultType>
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="summary">
    <summary>Exception occured when binding was invoked. Exception occured
    during invocation of JCA binding: "JCA Binding execute of
    Reference operation 'FileListing' failed due to: Exception
    occured when binding was invoked. Exception occured during
    invocation of JCA binding: "Could not instantiate
    InteractionSpec
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec due
    to: Cannot set JCA WSDL Property. Error while setting JCA
    WSDL Property. Property setListSorter is not defined for
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec Please
    verify the spelling of the property. ". The invoked JCA
    adapter raised a resource exception. Please examine the above
    error message carefully to determine a resolution. ". The
    invoked JCA adapter raised a resource exception. Please
    examine the above error message carefully to determine a
    resolution.</summary>
    </part>
    <part name="detail">
    <detail>Cannot set JCA WSDL Property. Error while setting JCA WSDL
    Property. Property setListSorter is not defined for
    oracle.tip.adapter.ftp.outbound.FTPListInteractionSpec Please
    verify the spelling of the property.</detail>
    </part>
    <part name="code">
    <code>null</code>
    </part>
    </bindingFault>
    </bpelFault>
    </fault>
    <faultType>
    <message>0</message>
    </faultType>
    </messages>
    Thanks,
    Ravi
    Edited by: Ravi Santosh on Apr 24, 2012 11:02 PM

  • Reading file from a folder : File dir = new File(URL+aFile_to_add);

    Hi,
    Trying to read files from a dir on my site using a JSP and bean. I've tried nearly every option for the filepath I can think of and it doesn't seem to be finding the file...
    Here's the bit:
    String URL = "images\\wedding_photos\\";
    File dir = new File(URL+aFile_to_add);
    String[] files = dir.list();
    It's working locally, but I obviously had to change the path from c://... to the above.
    The full code is listed below in the addWedding Method
    The method removes the .jpg from the file name and then writes the new file name to a database
    Thanks for any insight.
    Regards
    Jim
    public String addWedding(String aFile_to_add)
    String feedback = "unset in scrubWedding";
    try
    String URL = "images\\wedding_photos\\";
    Class.forName("org.gjt.mm.mysql.Driver");
    java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/rhwedd2_shop?user=**********&password=*******");
    java.sql.Statement statement = connection.createStatement();
    File dir = new File(URL+aFile_to_add);
    String[] files = dir.list();
    if (files == null)
    feedback = "Sorry, couldn't find the file "+aFile_to_add+"...no files have been added.";
    else
    for (int i=0; i<files.length; i++)
    // Get filename of file or directory
    String filename = files;
    String no_extension;
    //convert string array element into a char array
    char [] charsfilename = filename.toCharArray();
    int newlength = charsfilename.length -4;
    no_extension = String.valueOf(charsfilename,0,newlength);
    filesAdded = filesAdded+", "+no_extension;
    // Show the new file names in stack trace without extension
    //System.out.println("String no_extension " + no_extension );
    statement.executeUpdate("INSERT INTO items VALUES ('"+no_extension+"',5,'"+aFile_to_add+"')");
    // write to table with item_id and weddingid
    feedback = "The following files have been added..."+filesAdded;
    if (statement != null )
    statement.close();
    if ( connection != null )
    connection.close();
    catch(Exception e)
    feedback = "Into the catch";
    e.printStackTrace(System.err) ;
    return feedback;
    }//end addWedding

    String URL = "images\\wedding_photos\\";
    File dir = new File(URL+aFile_to_add); ok, ok, I'll answer...
    1) What gives you the impression that the relative directory "images\\..." exists (or, in other words, what makes you think your current directory is the parent of "images"?

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • File Adapter - Reading 2 files from sender and one file to receiver

    All - I am looking for a best solution for reading two files from sender and generating one file to the receiver.
    Here is the scenario
    Sender file s - A is a master file. B is a detail file; B will have a one to many records for each record of File A.. that is the relation ship between 2 files..  I am looking for a better solution to
    Example
    Input:
    File A will have a record like "summary1 ABC 1234"
    File B will have a record like "Detailfor Summary1 CDF 8679"
    Output:
    File C shall have a record "consolidatedofSummary&Detail ABC 1234 8679"
    1) read records of master row and detail row from these 2 files
    2) do the mapping to the receiver output format which it is creating for records with some harcoded values and based on the values from master and detail rows of sender file
    if I can accomblish reading sender files and do the mapping to the receiver , assume that mapping to the receiver format would not be cumbersome.
    please help me...
    Thanks

    Hi Gopal,
    Ur approach to the interface is perfect.... Go ahead.
    For selecting multiple files in source use Advanced Selection for files.. and specify the directory paths and also the file name shema...
    This will fetch the 2 files into the integration engine... then u map the 2 source files to one target file(2:1 mapping).
    Specify accordingly the receiver side FCC and test it end to end...
    If u face any prblm post here... some1 will help u out..
    Babu

  • 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

  • Download file from URL using ADF (urgent help required)

    We have the following requirement:
    On clicking a button we need to download the file present at a particular location(we have the URL).
    I have written the following in .jspx file :
    <af:commandButton  id="btn1" >
                        <af:fileDownloadActionListener contentType="text/plain; charset=utf-8" method="#{bean.getFile}"/>
    </af:commandButton>
    The corresponding method in bean is :
    public void getFile(FacesContext facesContext, OutputStream outputStream) {
    HttpServletResponse response = null;
    ServletOutputStream ouputStream = null;
    currUrl = getFileURL("ID", 281);
    response =
    (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
    try {
    ouputStream = response.getOutputStream();
    ouputStream.write(this.getFileBytes(), 0,this.getFileBytes().length);
    ouputStream.flush();
    ouputStream.close();
    } catch (IOException ioe) {
    System.out.println("IO Exception");
    public byte[] getFileBytes() {
    URLConnection urlConn = null;
    InputStream iStream = null;
    URL url;
    byte[] buf;
    int byteRead;
    try {
    url= new URL("http://hjhj:34104/test.pdf");
    urlConn = url.openConnection();
    iStream = urlConn.getInputStream();
    buf = new byte[5000000];
    byteRead = iStream.read(buf);
    if (byteRead > 0) {
    System.out.println("Downloaded Successfully.");
    return buf;
    } catch (FileNotFoundException fnfe) {
    System.out.println("File not found Exception");
    fnfe.printStackTrace();
    } catch (Exception e) {
    System.out.println("Exception:" + e.getMessage());
    e.printStackTrace();
    } finally {
    try {
    iStream.close();
    } catch (IOException e) {
    System.out.println("IO Exception");
    e.printStackTrace();
    System.out.println("File");
    return null;
    The file is opening in same window but in some encrypted format. My requirement is to :
    1. Have a pop (as in Mozilla or IE) which asks if I want to save the file or open.
    2. Depending on that the file should be opened in pdf format and not in browser same window neither in browser tab.

    Jdev version : 11.1.2.1.0
    in .jspx file : we have a button. On clicking the button file from URL should be downloaded. I have used fileDownloadActionListener in commandButton. Corresponding code :
    <af:commandButton  id="btn1" >
                        <af:fileDownloadActionListener contentType="text/plain; charset=utf-8" method="#{bean.getFile}"/>
    </af:commandButton>
    in bean class : the method corresponding to fileDownloadActionListener is :
    public void getFile(FacesContext facesContext, OutputStream outputStream) {
         HttpServletResponse response = null;
         ServletOutputStream ouputStream = null;
         response =(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
         try {
              ouputStream = response.getOutputStream();
              ouputStream.write(this.getFileBytes(), 0,this.getFileBytes().length);
              ouputStream.flush();
              ouputStream.close();
              } catch (IOException ioe) {
                   System.out.println("IO Exception");
    public byte[] getFileBytes() {
         URLConnection urlConn = null;
         InputStream iStream = null;
         URL url;
         byte[] buf;
         int byteRead;
         try {
              url= new URL("http://hjhj:34104/test");
              urlConn = url.openConnection();
              iStream = urlConn.getInputStream();
              buf = new byte[5000000];
              byteRead = iStream.read(buf);
              if (byteRead > 0) {
                   System.out.println("Downloaded Successfully.");
              return buf;   
        } catch (FileNotFoundException fnfe) {
              System.out.println("File not found Exception");
         } catch (Exception e) {
              System.out.println("IO Exception");
    The URL given in the code is for a file which can be a PDF file or an EXCEL file.
    My requirement is when i click the button:
    1. A pop should come (as in Mozilla or IE) which asks if I want to save the file or open.
    2. if i click on save file should save in a particular location.
    3. if i click on open it should open as PDF/EXCEL format and NOT in browser.
    Message was edited by: 1001638

  • How to read files from cq5..

    Hi,
    Here i want to get a pdf file from the "/content/myproj-data/docs/demo.pdf" path and then want to convert this into images...(I am using cq5.6.1)
    Whenever i started this process using the File I/O stream, i am not able to get the pdf file from the above path .....whenver i took from the static localpath (d://files/demo.pdf) i am able to fulfill my requirement ..
    Here whats happening is, when pass /content/myproj-data/docs/demo.pdf to the InputStream , it is changing as "\content\myproj-data\docs\demo.pdf" (Instead of "/" itz taking "\").
    Is there a better way to read pdf file from cq5 and convert into image??
    Please share!!!
    Thanks in advance
    Sony C.

    what kind is the different machine?
    if it is UNIX,you can use following code:
    URL url = new URL("ftp",server,port,file);
    InputStream reader = url.openStream();
    reader.read()
    if it is windows,you may be need to install a FTP agent.

  • How to play .wav file from URL in web browser embed

    Hi;
    I want to play a .wav sound file in embed default media player in IE. Sound file is on some HTTP location. I am unable to sound it in that player.
    Following is the code.
    URL url = new URL("http://www.concidel.com/upload/myfile.wav");
            URLConnection urlc = url.openConnection();
            InputStream is = (InputStream)urlc.getInputStream();
             fileBytes = new byte[is.available()];
             while (is.read(fileBytes,0,fileBytes.length)!=-1){}
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
             out.write(fileBytes);Here is embed code of HTML.
    <embed src="CallStatesTreeAction.do?ivrCallId=${requestScope.vo.callId}&agentId=${requestScope.vo.agentId}" type="application/x-mplayer2" autostart="0" playcount="1" style="width: 40%; height: 45" />1. If I write in FileOutputStream then it plays well
    2. If I replace my code of getting file from URL to my local hard disk. then it also works fine.
    I don't know why I am unable to play file from HTTP. And why it plays well from local hard disk.
    Please help.

    You'll have to ask the devleopers of sencha and phonegap.

  • Weblogic call a excel-file from URL doesn't open MSExcel but flat html

    Weblogic call a excel-file from URL doesn't open MSExcel but flat html
    Hi,
    WLS 10.3.5
    Forms 11.1.1.4
    I do migrate from AS10g to WLS 10.3.5 / Forms 11
    I get differences between FORMS 10 g / AS and FORMS 11 / WLS
    when call an excel-file with web.showdocument
    in 10g AS10g
    the call
    web.showdocumen('http://MyAS10_Server/myFormsMapping/myExcelfile.xls, _blank);
    opens a Windows-Box
    to decide
    open with ( MSExcel )
    or
    download and save as File
    in WLS 10.3.5 / FORMS 11.1.1.4
    the call with webcache Port 8090 as well as Port OHS 8888
    web.showdocumen('http://MyWLS_Server:8090/myFormsMapping/myExcelfile.xls, _blank);
    opens promptly the excel-File into the Browser as html-Format
    How to get the same way under WLS as before in AS 10g,
    config OHS ?
    regards
    get answer here :
    Weblogic: when call a excelfile from URL doesn't open MSExcel but flat html
    Edited by: astramare on Sep 12, 2011 11:59 AM

    Weblogic: when call a excelfile from URL doesn't open MSExcel but flat html

  • How to open Adobe Reader file from another native IOS application?

    There is an existing thread, but I want to re-open it because I think this is an important feature that we need badly.  I was wondering if there is any plan to add this feature so we can open PDFs directly into Adobe from the web / other apps.
    How to open Adobe Reader file from another native IOS application?
    Basically, we just want to use a custom URL scheme to open a specific document in the App.  Currently, this only opens the app but does not load the file.
    APB

    Not to hijack the conversation but I can explain why this would be useful for both the above case and another.
    What I believe Pavel is talking about is setting up a "URL Scheme" for the Adobe Acrobat iOS application so that you can easily open a PDF specifically in Adobe Acrobat iOS from other native applications and even from web applications opened within Safari. This is particularly useful if your application requires some of the specific features in Adobe Reader iOS to grant them the best experience possible and you want to encourage this.
    Another case: If you're using Adobe Livecycle's document security modules (that encrypts PDF files so that Adobe Acrobat must "phone home" to decrypt and view the document), these PDF's can only be viewed inside the Adobe Acrobat application and appear as blank in most other PDF readers. Having a URL scheme allows your application utilising this functionality to have a 1 click step to view the PDF rather than the current non-user friendly process:
    - Within Safari, touch the PDF link (appears as blank in the default Safari PDF reader, which in itself is confusing)
      - Touch "Open in..."
      - Touch "Adobe Acrobat"
    We have an immediate need for this functionality for the example above. I can resubmit it in a separate post if necessary.

Maybe you are looking for

  • How can I disable the "allow" bar?

    Whenever I click on a link within a window to go to another site, the (what I call it) the "allow" bar shows up and will not let me continue until I click on the allow. Tonight I tried to access my local library and was constantly shown this bar when

  • Everytime I try to use "send link" Firefox crashes! How can I fix this?

    Every time I click on "Send Link" to send a webpage to someone, Firefox will crash. This has only started recently, used to be able to do this. I believe the box says "Firefox has unexpectedly stopped working, then closes

  • IBooks Author Excerpt

    I have created a book in iBooks Author featuring multiple videos. How do I create an excerpt that would feature those videos for people to check out before they decide to buy the book?

  • UML Templates For Visio

    I heard Martin Fowler speak a week ago. He had a lot to say about UML 2.0, which I won't go into now. He said when he wants to create UML diagrams for books he uses Visio with a UML template that was allegedly better than the one M$ ships and was "av

  • Why would interlacing happen when rendering from 1920x1080 to 720x480

    I rendered an .mov from a Premiere CS6 project that is set for 1920x1080 and 23.976 fps. When I rendered it with the NTSC 24p widescreen setting to 720x480 I noticed a lot of interlacing that I did not see before in the project or on another render t