Close FtpURLConnection after FileNotFoundException

Hi all,
I use URL connection to connect to a URL via FTP protocol(code is below). I close the connection input stream in finally block and connection is released in normal flow. However if the file is not found the InputStream seems to be null and the connection remains open. The URLConnection seems to be a sun.net.www.protocol.ftp.FtpURLConnection instance. I tried to close() it also but althougn it prints the debug immediately before ftpConn.close() the conneciton remains open.
Is there a way to close this connection(I know this API is not guaranteed to work) or I should change to some other API as described [url http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp-p2.html]here?
Thanks for participating
Mike
Code follows...
    java.io.InputStream in = null;
    FtpURLConnection ftpConn = null;
    try
      URL addr = new URL("ftp://" + userName + ":" + password + "@" + server + "/" +  folder + "/" + fileName);
      URLConnection conn = addr.openConnection();
      if (conn instanceof FtpURLConnection) {
        ftpConn = (FtpURLConnection)conn;
      else{
        System.out.println("Not a sun FTP connection:" + conn.getClass().getName());
      in = conn.getInputStream();
      OutputStream out = <stream where I will read the data>;
      BufferedInputStream bis = new BufferedInputStream(in);
      int i;
      while((i=bis.read()) != -1){
        out.write(i);
      out.flush();
    catch(java.io.FileNotFoundException fnfe){
      //code to output the exception here
    catch(Throwable e){
      //code to output the exception here
    finally{
      try {
        if(null!=in){
          in.close();
      catch (Throwable ex) {
        System.out.println("Stream close error:" + ex);
      try {
        System.out.println("CONN CLOSE?");
        if(null!=ftpConn){
          System.out.println("CONN CLOSING");
          ftpConn.close();
      catch (Throwable ex) {
        System.out.println("Connection close error:" + ex);
....

Just to let you know: I did not find solution to the problem and changed implementation to use an FTP client library(I chose JavaShop JNet since it was used in another application of our company though it's not a recommended library).
The bad thing is that this adds one more library to the distrib :(
Mike

Similar Messages

  • SkillBuilders Modal Page... closes immediately after loading

    I would like to use the Modal Page plug-in from http://www.skillbuilders.com .*
    I installed the two sample applications from their web site with different results:
    The employee example works fine.
    The example with the modal feedback worked fine yesterday, but today it shrinks (after loading normally) so that I can't see anything but the bar with the window name and the close button.
    In my own application it's even worse:
    I have links in a table which should open a modal window on click.
    I tried several settings, but the only thing that's happening is that the window closes immediately after loading and showing the page for a half a second (or not at all).
    Leaving the "Auto-close On Element Selector" empty did not work. The default value "div#success-message" kept coming back until I replaced it with "null". But still no effect.
    Does anyone have any idea what could cause this behaviour?
    Best regards,
    Sabine
    The Security Settings for all three applications:
    Cache: Enabled
    Embed in Frames: Allow

    In the meantime I had the problem that the window didn't close at all, but I think I figured it out.
    So if the Modal Plug In does not work properly, check the following:
    <li>Does every process that should close the window have a 'Success Message' defined?
    <li>In the unconditional branch, is "include process success message" checked?
    <li>In the dynamic action, is "Auto-close On Element Selector" set to "div.t1success" in the true action?
    BTW: The "shrinking problem" described in the first post still exists - in IE. In Firefox, it works fine.
    Best regards,
    Sabine

  • I am facing problem with adobe illustrator cc in windows 8,it closes automatically after few secons,please help

    I am facing problem with adobe illustrator cc in windows 8,it closes automatically after few secons,please help
    [ link removed by moderator ]

    Sign in, activation, or connection errors | CS5.5 and later
    Mylenium

  • Forced to close RoboHelp after generating SSLs in order to edit content

    I have reported this as a bug, but wonder whether any of you have had similar experiences and, if so, how you resolved it.
    Have to close RoboHelp after generating SSLs in order to edit content
    Steps to reproduce bug:
    Open project from Visual Studio Source Control (Team Foundation Server).
    Select a Single Source Layout and generate the output.
    Try to edit a topic. The Check Out dialog box says "To modify this document, the files in the list below need to be checked out from version control. Do you want to check out these files."
    Click Yes.
    Results:
    The Cannot Complete Operation dialog box appears. "The files in the list below could not be checked out from version control. Exclusive access to these files is required to modify this document."
    Click Close, close RoboHelp, and restart RoboHelp.
    Expected results:
    The files should be checked out from version control with exclusive access when I click Yes to check them out.
    When I look in Source Control Explorer, the file I tried to check out is not even checked out. Even manually locking the file for edit from Source Control does not free the file for editing in RoboHelp.
    Thanks.
    Carol

    ''Keep until: I close Firefox''
    That's what I use for all cookies. If you start a new session every time you start Firefox, i.e., you don't resume the same session over and over, websites cannot track you 'across sessions' using cookies; you are a new person to them during each session (unless/until you log in).
    Note that "Flash cookies" need to be managed separately.
    As for this particular site, if you want to spend some time research it, you could install an add-on such as Firebug or the external Fiddler2 proxy. Both will show you each request made by the browser when you load a page. Then you can see which third party sites are involved and if you like make a specific entry to allow them in the Exceptions dialog.
    * https://addons.mozilla.org/en-US/firefox/addon/firebug/
    * http://www.fiddler2.com/fiddler2/ (more difficult to use for HTTPS sessions)

  • "Mail" application "closes unexpectedly" after a few seconds.

    “Mail” application "closes unexpectedly" after a few seconds.
    I use "Mail 1.3.11" to hnadle my e-mail. It works fine.
    This weekend, due to a problem with an address, the server of my University has delivered more than 1000 messages to my account.
    When I have opened "Mail 1.3.11" those messages have begun to enter into the "in" mail box. I have stoped it but anyway a good quantity of them have entered.
    I have already solved the server issue but now that I want to empty those messages from "Mail 1.3.11" I cannot since the application "closes unexpectedly" a few seconds after opening it without letting me do anything.
    How could I open and kept open my "Mail 1.3.11" until I am able to clean it?
    Thank you,

    [kmosx: Apps unexpectedly quit|http://discussions.apple.com/thread.jspa?messageID=607542&#607542]

  • Photoshop CC, Flash CC, After Effects CC, Dreamweaver CC all Closes right after opening????

    I have tried everything on the forums, but every time i open Photoshop, Dreamweaver, flash, after effects all with CC paid membership closes right after opening them. I have read the forums searched in the internet, update and downgrade the drivers on graphic card, sign in and out the adobe creative cloud, The one thing i notices is that when i open Photoshop in the notifications on my windows, it appears in the notifications that i register my product on adobe with ID but i have entered my Id with billing information an all when i click to continue it goes sign in then back to the address??. And in my products shows i have membership cloud, don't know what to do anymore! I have even uninstall the program and clean everything with adobe cleaning tool. I don't Know what to do!!!

    Have you found a solution, I am having same problem

  • Every CC app closes immediately after opening

    Hey there
    I've seen this question asked over and over again with a different answer most times. When I launch any CC app (i.e. DW & Photoshop), they'd close right after they finish loading. Only notable exception is Lightroom... but of course, that's not lightroom I need right now.
    - I cleared my previous CS6 install, even removed flash player. Ran Ccleaner twice including multiple rebbots. All fresh from any Adobe stuff.
    - I do not have GROWL installed on my system.
    - I did sign in/out/in the creative cloud app.
    - I did try different install location.
    - I tried ALL CAPS and no caps for my login.
    I got my 1 year subscription paid upfront; this is friday night &  I'm VERY upset as I do have work to do !
    Can someone please help ?
    Greg

    Hey there sorry to hear you're facing the same pb.
    Let me save you hours with the support queues. You won't fix this. Simple.
    The only thing that worked was to reimage my system. On a fresh install it worked right away. It's painful but really so much quicker than the time i spent trying to rootcause with the support folks on the phone.
    Once it's behind you, things are good.

  • Premiere CC closes right after opening it.

    Everytime i try open Premiere, photoshop or after effects they immediately close out without any warning or explanation. I also have lightroom from the cloud and that works perfectly. There are no error messages all of the programs simply just close right after they open. I have the programs installed onto a different drive as well, not sure if that help out with anything. Help! I bought these programs i'd like to use them to continue working!!!!

    See my reply in your other message Lightroom is the only program that will run

  • Creative Cloud closes right after opening.

    Hello.
    My creative cloud apps close right after I open them.
    For an example I'll take photoshop. I click it, I get the photoshop logo.
    After the logo disappears I get the Photoshop screen. But it only remains open for a few seconds, and then closes right after.
    No error messages, no warning, it just closes.
    It's not just PS, every app I have installed has the same reaction.
    I have tried:
    The font thing I found on here. - Didn't work
    Reinstalling the apps - Didn't work
    Reinstalling Creative Cloud - Didn't work
    Windows 7
    Intel(r) Core(TM) i5-2450m CPU @ 2.50GHz

    http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
    Mylenium

  • How do I close apps after I have updated them? I have 30 apps saying open.

    How do I close apps after I have updated them? I have 30 apps saying open after I have updated them.
    IPin other words, all of my updates are still showing on the screen after they have been updated.

    The word 'OPEN' next to the name of the app doesn't mean the app is running. Instead, it is a button you can use to launch the App.
    If you don't do anything, then the list will eventually disappear on its own, along with all those buttons saying 'OPEN'.

  • Hi, I just installed my Creative Suite 6 and the programs close right after launching (for about 5 seconds) with no dialog box about an error. I have tried uninstalling and re-installing but still the same thing. Help pls!

    Hi, I just installed my Creative Suite 6 and the programs close right after launching (for about 5 seconds) with no dialog box about an error. I have tried uninstalling and re-installing but still the same thing. Help pls!

    Sign in, activation, or connection errors | CS5.5 and later
    Mylenium

  • Photoshop closes immediately after starting up. Lightroom and Bridge works fine

    Photoshop closes immediately after starting up. Lightroom and Bridge works fine

    Is there some reason for not mentioning the version, the OS, …?
    Boilerplate-text:
    Are Photoshop and OS fully updated and have you performed the usual trouble-shooting routines (trashing prefs by pressing command-alt-shift/ctrl-alt-shift while starting Photoshop until the appropriate dialog appears after making sure all customized presets like Actions, Patterns, Brushes etc. have been saved and making a note of the Preferences you’ve changed, 3rd party plug-ins deactivation, system maintenance, cleaning caches, font validation, etc.)

  • IPhone apps close immediately after opening

    I have tried :
    - iPhone reboot (several times)
    - install a new app through iTunes (several times)
    - deauthorize and reauthorize the computer (several times)
    - uninstall all apps and reinstall
    - reset all iPhone settings
    - iPhone restore
    - scour all discussion threads for solutions
    to no avail. This all started after weeks of needing to reauthorize the computer every sync, then halfway syncing when I was away from an internet connection. I stopped it in attempt to not lose all of the apps, and it didn't delete the apps, but then they would close just after launch. Any more ideas? Thanks.

    I used to have the same problem. the iPhone was acting weird so I tried to reboot it but it didn't work so I forced-rebooted it (holding Power and Home simultaneously) and since then all the apps that didn't came with iPhone fail to launch (you see the first screen for half a sec then you're back to the home screen).
    It disappeared when I synced it with iTunes.
    Message was edited by: aaSwebmaster

  • Why do apps close immediately after opening?

    I updated to iOS 4.3.3 on my iPad, now my apps close immediately after I open them.
    Built-in apps are OK, but all my added apps no longer run!
    Help!
    I have rebooted using the sleep button held down for 10 seconds.   No joy.
    Now, I was advised to hold down sleep button and home circle button at same time and disregard the red bar... this reboots to Apple circle, but still apps close really fast after I try to open them.
    This actually started several hours after my update, not right away, but that is all that changed.
    Very frustrating!

    Jeanne ... You answered my post in a totally different thread but I did read it. If the problem is in the OS, why do the built in Apple apps not cause the iPad to crash? That reasoning makes no sense to me. Did you try closing all of the apps like I suggested and then restart?
    Another way to approach this is to remove all of the apps from your iPad. Do this by removing them when you sync. Simply uncheck all of the non Apple apps and sync. Then - one or two apps at a time- add them back on to the iPad by resyncing. Use those one or two apps and see if they crash. If they don't crash, add one or two more apps and try those. Keep repeating the process until the iPad starts to crash again. You should be able to narrow down which app is causing the problem.
    Are you sure that all of these apps are compatible with 4.3.3. as well? Check in the app store and make sure that they are.
    Message was edited by: Demo

  • Final Cut Express HD (3.5) closes right after opening?

    Hi,
    I believe years ago I had this same issue and it was as simple as deleting the preferences (??).
    Basically, what's happening is I just installed FCE HD (3.5) on my G4. I meet the system requirements to run the application AND Soundtrack Pro and LiveType open and run fine. FCE closes immediately after opening and then I get an error: "The Application Final Cut Express Quit Unexpectedly."
    Any ideas?
    Thanks!

    Yeah, sorry for being so confusing. That's exactely what I did. Since my main HD is 500Gb and my secondary drive is 120Gb, I just copied all the necessary files to the 500, formatted the 120, reinstalled OSX, and booted to it. The intention was to let the FCE software think it was installing on a fresh drive (which, it was).
    However, even then it won't let me install FCE. Just LT and Soundtrack. ?? I'm a bit confused because the system requirements for Soundtrack and LT are the same for FCE.
    I'm trying to install it on a Dual 1.25ghz G4 Quicksilver with 1.5Gb Ram. ??
    The funny thing is I WAS able to install the complete program initially when I got it. I had a previous copy of Final Cut Express (1) on my main drive. I ran the FCE HD installer, and the program installed just fine. However, it kept closing right after it would open. I figured it was a preference conflict between the newer version (3.5) and the old version (1.1). So, I've done my best trying to erase all evidence of FCE ever being on the drive and still get nowhere ??
    Thanks!

Maybe you are looking for