How to cancel downloading in JAVA FTP?

I tried to write a java ftp client to transfer files within our network. One of very usefully function I want to add is to cancel the transfer while files
are downloading or uploading. I can do this on file uploading by closing "ftpclient.put(filename) methods at anytime, but have trouble on closing "ftpClient.get(remoteFilename)". When I tried to close it by using "in.close()", the program stucked. I even tried to kill the thread, but no luck. Can any one give me a hint? Here is the code:
protected void downloadfile ()
byte [] buffer = new byte[BUFFER_SIZE];
try{
FileOutputStream out = new FileOutputStream(Localfilename);
InputStream in = ftpClient.get(remoteFilename); //downloading
// Write to local file
while (true && !cancelORnot)
// write to file
} catch ( Exception ex) { }
finally
try {
if (out ! = null)
out.close(); // this can be closed at any time
if (in != null)
in.close(); // This one stucked if it is in the middle
// of downloading and can not disconnect to the
// ftp server
catch ( IOException ex)
Thanks!

Thank you for replying. I am sorry I forgot including FTP API
information.The FTP API I used is from SUN, JDK, sun.net.ftp.FtpClient. The method is " InputStream in = ftpClient.get(remoteFilename)"and "in.close()" should close downloading. while it is still downloading, in.close() will not work and hang my program on forever. I am just wondering if there is trick to close downloading whenever I want especially in case that network connection is too slow and I want to cancel the job.

Similar Messages

  • How do I download legacy java 6.0 SE runtime?

    How do I download legacy java 6.0 SE runtime?

    I had the same problem running cs6 even when I upgraded java to 8... the thing is that you still need 6 even if you have 8.
    this link was the only thing that worked for me

  • How to cancel downloading process in JAVA ftp?

    I tried to write a java ftp client to transfer files within our network. One of very usefully function I want to add is to cancel the transfer while files
    are downloading or uploading. I can do this on file uploading by closing "ftpclient.put(filename) methods at anytime, but have trouble on closing "ftpClient.get(remoteFilename)". When I tried to close it by using "in.close()", the program stucked. I even tried to kill the thread, but no luck. Can any one give me a hint? Here is the code:
    protected void downloadfile ()
    byte [] buffer = new byte[BUFFER_SIZE];
    try{
    FileOutputStream out = new FileOutputStream(Localfilename);
    InputStream in = ftpClient.get(remoteFilename); //downloading
    // Write to local file
    while (true && !cancelORnot)
    // write to file
    } catch ( Exception ex) { }
    finally
    try {
    if (out ! = null)
    out.close(); // this can be closed at any time
    if (in != null)
    in.close(); // This one stucked if it is in the middle
    // of downloading and can not disconnect to the
    // ftp server
    catch ( IOException ex)
    }

    How does the ftpClient.get("fileName") work? Also, are you running everything in the EventDispatchThread? If your running everything in the EventDispatchThread then ftpClient.get() will need to finish before an event can be handled.
    If thats the case, you could use a SwingWorker to do the downloading so that the Event Thread is available to handle the cancel event.

  • How to open/download a .java file instead of it opening as a txt in a new Firefox tab?

    Hi,
    I need to download/open on my computer a .java file, but Firefox does not give me an "Open" or "Download" box, instead, it opens the java file as text in a new tab.
    How do I download/open it on my computer?

    I assume that you are referring to a JavaScript file.
    Java and JavaScript are different languages.
    To avoid confusion, see:
    *http://kb.mozillazine.org/JavaScript_is_not_Java
    If the server sends the file as text/plain then Firefox will open the file in a tab if you left click and not offer to download/save the file.
    In that case you need to save the file via the right-click context menu or the File menu.
    You will have to right-click the link and use "Save Link As" to save such a file directly instead of left-clicking the link.

  • HT5772 How to cancel downloading update?

    I accidently hit the wrong button. How can I cancel downloading update?

    Hit pause... Trash the download from the download folder. Also clear the downloads... in Safari.

  • How to cancel downloading app in ipod touch that status is "waiting"??

    I've choose "update all" from app store. Because a slow connection, all app that i've update is still "waiting" till now. I want to cancel the process and I've tried to reboot but still does'nt work. So, how to cancel those "waiting" app???

    iOS 4.3.1 has features for deleting it before you started downloading. iOS 4.2 does not

  • HT3662 how to cancel downloading Mavericks while in progress on macbook pro

    I started downloading latest Mavericks OS and realized I had already downloaded the latest version. Cannot cancel the download.
    What do I do?

    Thank you for replying. I am sorry I forgot including FTP API
    information.The FTP API I used is from SUN, JDK, sun.net.ftp.FtpClient. The method is " InputStream in = ftpClient.get(remoteFilename)"and "in.close()" should close downloading. while it is still downloading, in.close() will not work and hang my program on forever. I am just wondering if there is trick to close downloading whenever I want especially in case that network connection is too slow and I want to cancel the job.

  • HT2347 How to cancel downloading files now

    How do you cancel a presently downloading file?

    Hit pause... Trash the download from the download folder. Also clear the downloads... in Safari.

  • HT201272 how to cancel download of movie

    My son purchased a movie and it will take 3 hours to download into his iPod! It is preventing other downloads and we would like to know if gthere is a way to not have to download the movie and just cancel it!

    How can I cancel the download of a movie on iTunes?

  • How do i download Apples Java SE 6?

    I downloaded Oracle's Java 7 and i need to get back to Java 6 to run certain applications. When i try apples help to revert back, i find that Java 6 no longer exists on my computer. How do i get it back so that i can switch to run on it.
    Thanks in advance for any help...

    William Lloyd wrote:
    You can only do Java 6 applications (i.e. "java" from the command line).  Java 1.6 applets are forever dead.  Gone.  Period.
    Utter nonsense. I've both installed on Mtn Lion. http://support.apple.com/kb/HT5559 explains how to select the SE 6 plug-in. The  requisite 1.6.0 JDK resides in the /System/Library/Java/JVM folder. If you want to determine the installed Java 7 JRE, run this in the Terminal app:
    /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
    This is what's on my machine:
    java version "1.7.0_21"
    Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
    Whereas, for Java 6, the java -version command shows:
    java version "1.6.0_45"
    Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-10M4406)
    Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
    Java for OS X 2013-003 updates the Apple-provided system Java SE 6 to version 1.6.0_45 on Lion and ML volumes. Now, it might be that the OP will have to extract and install a previous SE 6 JRE from an applicable OS installer app.

  • Does anyone know how to cancel download of a purchase?

    I bought a show, and now I dont want it. I havent yet downloaded it. How do I cancel my download and get the rest of my qeue downloaded?

    Send an email here with the details.
    http://www.apple.com/support/itunes/musicstore/songs/

  • How To Cancel Download of Podcast

    I recently tried downloading previous episodes of a Fringe Podcast through Itunes on my computer unsuccessfully so I then tried to do the downloads on my Iphone through Itunes. Again it was unsuccessful this time because the files were too big if I remember correctly..........anyways heres my problem......when I go to the download screen on my Iphone the 3 Fringe Podcats still remain there, 2 are stuck on processing and the other says waiting. I want to remove them all from that download screen but do not know how. Any help would be greatly appreciated.

    Try resetting the iPad and see if the podcasts will finish downloading, then delete them if you don't want them.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • 12 day Christmas Free downloads: How to cancel download ?

    Hi,
    have agreed to download the TV-Package. It appears that the three
    TV sessions are more than 200 MB each.
    Now I would like to stop the download and cancel it completely.
    "Side-Slide" does not work. I can stop the download but can not cancel/delete it.
    Any advice ?

    Thanks,
    after restarting iTunes I had the 3 files in the "Download" area. Deleted files in iTunes.
    But they are still on the iPad, waiting for the download. After next sync, they are back in the download area of iTunes again. Ready to be deleted
    btw. it is not that I complain about the free files: It just takes my download bandwith for a day......

  • How to cancel downloads

    I would prefer not to receive the HD versions of tv downloads.  They take up way too much space on my drive.  Is there any way to prevent the initial download?  I am currently coping by simply deleting the files once downloaded.

    "I would prefer not to receive the HD versions of tv downloads."
    Then  don't purchase them.  Just buy the SD version.
    You cannot delete waiting downloads.  You would have to let them download then delete them.

  • Guide me how do download the Java Edition of the Netweaver Sneak preview

    Can Some one please guide me how do I download the Java edition , I have Core FTP installed, On doing a save target as it asks me whehther to use Core FTP for file transfer, on choosing yes it a status window which says connecting,with source and destination values and then gives a message NW04SneakPrevJavaSP11.part1.rar-File not found....
    and thereafter the File Download Dialog still remains trying to find for the source location.....
    Some Kindly guide me the right way to do it

    Hi Paras,
    I just tried to download, no problem. I click on <i>Downloads -> Web AS -> New! Sneak Preview -> Download file 1</i> and get a popup where to save the file.
    Please try again with the given path.
    By the way, it should be enough to post your problem once
    Hope that helps!
    Best regards
    Renald

Maybe you are looking for

  • Register new report in GL module

    Hi all Is there some some doc where i can find the steps to register a new report in oracle apps? I have to build a report from scratch, an i want to register it, in oracle apps in the GL module. Thanks in advance Soni

  • Not able to acess BIOS setting in G580

    I have a G580 Model Lenovo Laptop. I wanted to Dual-Boot it with Linux/Ubuntu. I have learnt that it is not possible due to UEFI Mode in BIOS. I Searched it everwhere, and every solution sums up to changing UEFI to Legacy Mode in Boot Menu. Thing is

  • Question about carDemo - wrong URL shown

    Made carDemo running on my machine successfully. Kool stuff! Found something wrong, the question may seem silly. The URL shown on my brower is always the previous page: e.g. http://localhost:8080/jsf-cardemo/chooseLocale.jsf -- for the store front pa

  • Spry Navigation Mac vs Win

    Created Spry menu bar. works fine on Mac/Safari. On Win XP/IE 7 it works but looks bad- the length of each box differs based on text length. Have been told, text within the boxes does not show in IE6. Help.

  • I want to buy an adobe product that cuts the background from a picture very fast. Faster than photoshop cs6

    I Want to buy a photoshop product that can cut my background from a picture very fast. Faster than ps6