Pdf file transfer using ftp in java

Hi,
I am tried to get a pdf file from ftp. I am using the following code. This code works fine with .txt files but not with .pdf files. The pdf file generated is empty.
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import org.apache.commons.net.ftp.FTPClient;
public class FTPConn {
       public static void main(String[] args) throws FileNotFoundException {
        FTPClient f = new FTPClient();
        try {
            f.connect(ip);
            f.login("username", "password");
            File dir = new File("dir");
            dir.mkdir();
            File myFile = new File(dir, "myfile19.pdf");
            myFile.createNewFile();
            FileOutputStream fout = new FileOutputStream(myFile);
            String content= fout.toString();
            boolean success = f.retrieveFile("/location on ftp/ftp.pdf", fout);
            System.out.println("Content :"+content);
            if (success) {
                fout.flush();
                fout.close();
            } else {
                System.out.println("Reterive failure");
            Desktop d = Desktop.getDesktop();
            d.open(myFile);
        }catch(Exception e){
            e.printStackTrace();

Hi,
I am tried to get a pdf file from ftp. I am using the following code. This code works fine with .txt files but not with .pdf files. The pdf file generated is empty.
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import org.apache.commons.net.ftp.FTPClient;
public class FTPConn {
       public static void main(String[] args) throws FileNotFoundException {
        FTPClient f = new FTPClient();
        try {
            f.connect(ip);
            f.login("username", "password");
            File dir = new File("dir");
            dir.mkdir();
            File myFile = new File(dir, "myfile19.pdf");
            myFile.createNewFile();
            FileOutputStream fout = new FileOutputStream(myFile);
            String content= fout.toString();
            boolean success = f.retrieveFile("/location on ftp/ftp.pdf", fout);
            System.out.println("Content :"+content);
            if (success) {
                fout.flush();
                fout.close();
            } else {
                System.out.println("Reterive failure");
            Desktop d = Desktop.getDesktop();
            d.open(myFile);
        }catch(Exception e){
            e.printStackTrace();

Similar Messages

  • Error in Rcvr File Adapter using FTP ?

    Hi @,
    I am getting the follwoing error while trying to put file in the folder thru Rcvr File Adapter using FTP and it is giving me following error :
    java.io.FileNotFoundException :(Permission Denied )
    I have verified the permissions on the folder and it is having write permissions.
    Please suggest Its urgent.
    REgards

    hi amit,
    can you
    1. check whether the access to FTP is Authenticated, if so provide the username and password
    2. try giving different file name at the receiver end
    3. try normal ftp commands to access the folder
    regards
    Ramesh P

  • Firefox 33 doesn't display a pdf file when using the response object

    Firefox 33.0.2 does not display pdf files when using the code below from an asp.net program, which works for previous versions of Firefox, and also works with IE. I'm using the built-in pdf viewer. All of my plugins are disabled.
    Dim strPDF As String
    strPDF = Session("filname") 'pdf filename
    Response.Clear()
    Response.ClearHeaders()
    Response.Buffer = True
    Response.ContentType = "application/pdf"
    Response.CacheControl = "Private"
    Response.AddHeader("Pragma", "no-cache")
    Response.AddHeader("Expires", "0")
    Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate")
    Response.AddHeader("Content-Disposition", "inline; filename=" + strPDF)
    Response.WriteFile(strPDF)
    Response.Flush()
    Response.Close()
    Response.Clear()
    Response.End()
    Session("filname") = ""

    Thanks cor-el. You pointed me in the right direction. It appears to me that a reported Firefox 33 bug with the handling of compression (Transfer-Encoding: chunked) is the culprit (https://support.mozilla.org/en-US/questions/1026743). I was able to find a work-around by specifying the file size and buffering. Below is my code, with some code from http://www.codeproject.com/Questions/440054/How-to-Open-any-file-in-new-browser-tab-using-ASP.
    Dim strPDF As String
    strPDF = Session("filname") 'pdf filename
    Dim User As New WebClient()
    Dim FileBuffer As [Byte]() = User.DownloadData(strPDF)
    If Not (FileBuffer Is Nothing) Then
    Response.Clear()
    Response.ClearHeaders()
    Response.CacheControl = "Private"
    Response.AddHeader("Pragma", "no-cache")
    Response.AddHeader("Expires", "0")
    Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate")
    Response.ContentType = "application/pdf"
    Response.AddHeader("content-length", FileBuffer.Length.ToString())
    Response.BinaryWrite(FileBuffer)
    Response.Flush()
    Response.Close()
    Response.Clear()
    Response.End()
    End If
    Session("filname") = ""

  • Unable to read PDF files created by FTP Adapter

    Hi,
    I am unable to read pdf files generated by FTP Adapter with its default settings.
    Can anybody guide me how to proceed with it. I guess I need to change something in encoding mechanism in FTP Adapter Outbound Connection Pool, but not sure what has to be.
    Thanks,
    Richa

    Hi all,
    I have got its solution. I was unable to read .pdf files because FTP adapter  was sending the files just by changing the extension from .txt /.xml to .pdf that is the reason that it was not readable.
    We had to write an java code to convert .xml file to .pdf file and then paas it to FTP ADapter.
    Thanks

  • I use iMac desktop. I can't save web pages as PDF file by using Firefox, but by Safari is fine.

    I'm using Mac OS X 10.6.4. Today, I tried to save my email content as a PDF file. However, I only got a PDF file that have partial content of email. Then I adjust the printer setting and did it again, then I only got a blank PDF file. There was nothing inside. Then I tried to save email as a PDF file by using Safari browser. And I got a complete and sucessful PDF file. I usually save web pages or web mail, online receipt as PDF file by use Firefox. But since I have updated to the new version, there were many problems with my Firefox. I tried to restore all my application and made Firefox in the old 3.6.3 version which I used to have no problem. But now still not working.

    I solved it for myself: it was my HP smart-web printer crap that was a plug in and add on for firefox that somehow automatically got installed when I upgraded to 5. I disabled both in the add-ons manager, and voila, printing is working.
    It seems there are many things, like this and the Google toolbar, that were screwed by the oddly fast update to 5. Looks like Mozilla didn't give anybody any notice! Must've been some really bad security hole.

  • I use iMac desktop. I can't save web pages to PDF file by using Firefox, but by Safari is fine.

    I'm using Mac OS X 10.6.4. Today, I tried to save my email content as a PDF file. However, I only got a PDF file that have partial content of email. Then I adjust the printer setting and did it again, then I only got a blank PDF file. There was nothing inside. Then I tried to save email as a PDF file by using Safari browser. And I got a complete and sucessful PDF file. I usually save web pages or web mail, online receipt as PDF file by use Firefox. But since I have updated to the new version, there were many problems with my Firefox. I tried to restore all my application and made Firefox in the old 3.6.3 version which I used to have no problem. But now still not working.
    ''Duplicate post, continue [https://support.mozilla.com/en-US/questions/746583 here]''

    hello jlzibell, please go through the troubleshooting steps described at [[Websites say cookies are blocked - Unblock them]].

  • Recently my adobe is taking much longer to load PDF files that used to open immediately

    recently my adobe is taking much longer to load PDF files that used to load almost instantly

    Look at this comprehensive trouble shooting document;
    https://discussions.apple.com/docs/DOC-3353
    I suggest that you start with SMC and PRAM resets.
    Then  a Safe Boot.
    Ciao.

  • I woke up at 3am to find my MacBook Pro in the middle of a file transfer using AirDrop.

         I woke up at 3am to find my MacBook Pro in the middle of a file transfer using AirDrop. I had not accepted any file transfers via AirDrop as I was asleep so I am a bit confused by all the posts that say that the only way it will work is by the end user accepting a request to transfer files. I am on a home network which has both a soft and hard firewall. I checked my firewall logs and have no signs of intrusion or intrusion attempts. I checked my network map to see see if someone had brute forced my router and was using it but the only assets listed were mine. My router is set up to not be accessable from wireless computers, and is filtered to only allow use by a assets in the MAC Address list. I am an IT by trade but this is my first mac so I am not completely savy in the ways of the ways of macdom. I have found several posts with suggestions on how to turn off and came up with the following terminal command "defaults write com.apple.NetworkBrowser DisableAirDrop -boolean YES". My question is this, how is it possible that my AirDrop was activated and in the middle of a file tranfer if I did not initiate it? I do have a MacMini on my network but its WiFi is turned off so the transfer was not with it. I have read on different posts that you cannot AirDrop if the computer is not on the same network but there were no foreign assets on my network. So my question is this
    1. If AirDrop can not be used with another computer if it is not on the same network, how was it being used?
    2. How can AirDrop be used to xfer files if I did not accept or initate it?
         It seems to be a pretty big security hole to me. Any suggestions or help would be greatly appreciated.
    Ethan

    It could just be a bad disc - I use Verbatim and have only had one fail in a ten-year time period. Try getting a batch of Verbatims and see if you have any problems. I didn't even know that there were Kodak branded discs...
    Clinton

  • Saving a Text data to a PDF file without using print option

    Hi,
    I want to save a Text to a PDF file. I want to assign the path of the PDF file as a default one.
    If I use Print options, then it ask for the file path at the run time.
    Is there any method to save to a PDF file without using print option in Labview 8.2.
    Regards,
    Raja

    This question comes up a lot. Did you try searching? It depends on the PDF printer driver that you're using. See here, here, here, ...

  • Steps for File Transfer through FTPS...!!!

    Hi ,
    Can anyone please tell the steps for file transfer with FTPS.
    Does PI file adapter has bulilt in feauture to handle this? or
    Do we need to deploy anything to handle this?
    Do we need to install any certificates by requesting from partner or It will do the encryptions/authentications on its own?
    Any additional Steps we need to mention in File receiver adapter while we send the file through FTPS?
    File is going through port 1090(unsecure connection) but it is not going through port (990) which is a secure connection.
    Please suggest me.
    Thanks
    Krupakar

    Hi Shabarish,
    We got the certificate from the partner and loaded into the trusted CA's. I tried running by giving
    Connectivity Security as "FTPS for Control and Data Connection" and Command Order as "AUTH TLS,USER,PASS,PBSZ,PROT"
    Ip: XXX.YY.YY.ZZZ
    Port: 990
    User and pwd.
    and I am getting the same below error
    Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Error when getting an FTP connection from connection pool: com.sap.aii.af.service.util.concurrent.ResourcePoolException: Unable to create new pooled resource: iaik.security.ssl.SSLCertificateException: Peer certificate rejected by ChainVerifier
    I tried by selecting different options like
    1. Without selecting the X509 certificate for client authentication.
    2.  Keystore as TRUSTED\view\entry-cert
       X509 certificate and private key as TRUSTED\view\entry-cert
    3. Keystore as TRUSTED\view
      X509 certificate and private key as TRUSTED\entry-cert
    4.Keystore as "view"
      X509 certificate and private key as "entry-cert"
    Please help me in this.
    Thanks
    Krupakar

  • How to insert my signature in pdf file by using adobe?

    how to insert my digital signature in pdf file by using adobe

    Hi vani.boddu,
    If you're using Adobe Acrobat then refer the below links:
    Video : http://tv.adobe.com/watch/i-didnt-know-acrobat-xi-could-do-that-tutori als/sign-pdf-files-electronically/
    Document : http://help.adobe.com/en_US/acrobat/X/standard/using/WSAC8084C2-14F7-4 841-9EF8-92106D22C3DB.w.html
    If You're Using Adobe Reader
    Please refer : http://helpx.adobe.com/reader/using/sign-pdfs.html

  • HT204144 File transfer using Airdrop from iphone to Macbook Pro

    File transfer using airdrop form Macbook Pro to iphone is working...but from iphone to Macbook Pro is not working, Why?

    Hi Brok25;
    Thanks for the question.  The resource below explains the specs and settings that are needed for AirDrop.  Check the settings and look to see if your MacBook Pro is listed.
    Mac Basics: AirDrop lets you send files from your Mac to nearby Macs and iOS devices - Apple Support
    http://support.apple.com/en-us/HT203106
    Sending files to and from an older Mac
    If a Mac you're using with AirDrop was manufactured before 2012, you can send and receive files with other Mac computers.
    On the sending Mac, click "Don't see who you're looking for" in the AirDrop window.
    Select the option to "Search for an Older Mac."
    On the receiving Mac, open a new Finder window and click AirDrop in the sidebar.
    Tips for sending files
    Make sure Wi-Fi and Bluetooth are enabled on your Mac and your iOS device. Although you don't have to connect to a specific network, Wi-Fi needs to be on to send and receive files using AirDrop.
    Move your devices closer together. AirDrop is designed to work within a range of approximately 30 feet (9 meters). If you need to send a file to someone farther away, consider using File Sharing, iCloud, or email instead.
    If you're using a firewall on your Mac, you won't be able to receive AirDrop files if you have enabled "Block all incoming connections" in the Security & Privacy pane of System Preferences.
    Make sure your devices meet system requirements for AirDrop.
    System Requirements
    To see if your Mac works with AirDrop, make sure you’re in the Finder by clicking the desktop (the background area of your screen), or by clicking the Finder icon in the Dock. Then, check to see if AirDrop is listed as an option in the Go menu. If you don't see AirDrop listed, your Mac doesn't support this feature.
    In order to transfer files between a Mac and and an iPhone, iPad or iPod touch
    your iOS device needs to include a lightning connector 
    your iOS device needs iOS 7 or later installed
    your Mac needs to be a 2012 or later model with OS X Yosemite installed
    Your Mac and iOS device both need bluetooth and Wi-Fi turned on. You do not have to be connected to a specific Wi-Fi network. 
    To transfer files between two Mac computers, you need the Mac models listed below with Wi-Fi turned on and OS X Lion or later installed.
    MacBook Pro (Late 2008 or newer)*
    MacBook Air (Late 2010 or newer)
    MacBook (Late 2008 or newer)*
    iMac (Early 2009 or newer)
    Mac Mini (Mid 2010 or newer)
    Mac Pro (Early 2009 with AirPort Extreme card, or Mid 2010)
    *The MacBook Pro (17-Inch Late 2008) and the white MacBook (Late 2008) do not support AirDrop.
    For help identifying your Mac, choose About This Mac from the Apple menu. You can refer to the Apple Support website to find out if your iPhone, iPad or iPod Touch includes a lightning connector. 
    Cheers,
    - Judy

  • How can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    how can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    let's say a registration form, there is only 1 full address provided in my registration pdf, but applicant could have more than 1 address, so i have to make it more flexible to extend the address page no matter how many addresses that applicant provided, i have use adobe acrobat pro to edit the form properties. but dont know how to extend/duplicate a page in felxible times.
    Please advise~ tks so much!!! George

  • Open *.PDF file by using ABAP program

    Hi,
    Can anyone please tell me about  " how to  open a PDF file by using an ABAP program".
    Regards,
    Prasanth

    Welcome to SDN.
    Refer this class - CL_GUI_PDF_VIEWER
    You may refer this thread also -
    Re: Open Jpg, Excel, word, pdf files from SAP screen.
    Regards,
    Amit

  • Creating an Adobe .pdf file without using the Adobe printer

    Is it possible to create a .pdf file by using Acrobat or Microsoft Word or any other program without using a printer driver? So far, when I remove the Adobe printer, I cannot create a .pdf file, as it is looking for the printer and printer driver. Is it even possible to create a .pdf without using, or having, a PDF printer of any sort? Any help on this issue would be most helpful. Thanks.

    I was trying to find a way to create PDFs without using the Adobe printer, or any PDF printer. I posed this question to see if there was a way to create a PDF without the aid of a printer or not. I mean, I know how to reinstall the Adobe printer, since I had to to see if there was another way to go about creating without using the printer. I am just curious if there is a way to create a PDF file without the aid of the Adobe printer or other PDF printers.

Maybe you are looking for

  • How do I save the text I have typed in a PDF file in Adobe, then mail it.

    How do I save text that I have typed in a PDF file in adobe and then mail it Currently goes through without text

  • SSL code returns HTTPClient.HttpURLConnection

    Challenge: connect to a secured site to post some data. Issue: tried several ways, HTTPSURLConnection is not getting obtained, just HTTPClient.HttpURLConnection every time. Environment: OS - Linux, version 2.6.9. java.version: 1.5.0_10. Server: Oracl

  • How do I remove cache?

    I'm trying to upgrade to the latest version of icefaces and it says in the install notes to: On Windows only, manually remove the JSC2 internal cache files or the installation of the newer extension library will fail silently. Where are the 'JSC2 int

  • Error: Could not find a match for... ?

    Hi, I am trying to compile some code using Studio 10/11 which appears to compile cleanly using a bunch of different C++ compilers (xlC, aCC, VC, g++) but is failing using the C++ compiler in both Studio 10 and Studio 11 with: "test.cpp", line 18: Err

  • Looking for a good configuration for SoundBlaster X-Fi

    This really is painful to find a good setting to enjoy gaming.Anyone that can link a good configuration to start me off that they personally feel takes full advantage in deli'vering a great experience for gaming. I really appreciate any help.