Results 1 to 8 of 8
  1. #1
    moral is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Problem with ftp

    Hi
    I have problem with send xml file via ftp. For FTP I use a Apache commons-net-3.2. Here is code (from www):
    Java Code:
     public static void main(String[] args) throws Exception {
              System.out.println("Start");
              FTPUploader ftpUploader = new FTPUploader("localhost", "user", "pass");
              ftpUploader.uploadFile("/home/moral/cat_source_ftp/teesstt.txt", "t.txt", "ftp/");
              ftpUploader.disconnect();
              System.out.println("Done");
         }
    Java Code:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    
    import org.apache.commons.net.PrintCommandListener;
    import org.apache.commons.net.ftp.FTP;
    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPReply;
    
    public class FTPUploader {
        
         FTPClient ftp = null;
        
         public FTPUploader(String host, String user, String pwd) throws Exception{
              ftp = new FTPClient();
              ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
              int reply;
              ftp.connect(host);
              reply = ftp.getReplyCode();
              if (!FTPReply.isPositiveCompletion(reply)) {
                   ftp.disconnect();
                   throw new Exception("Exception in connecting to FTP Server");
              }
              ftp.login(user, pwd);
              ftp.setFileType(FTP.BINARY_FILE_TYPE);
              ftp.enterLocalPassiveMode();
         }
         public void uploadFile(String localFileFullName, String fileName, String hostDir)
                   throws Exception {
              try(InputStream input = new FileInputStream(new File(localFileFullName))){
              this.ftp.storeFile(hostDir + fileName, input);
              }
         }
    
         public void disconnect(){
              if (this.ftp.isConnected()) {
                   try {
                        this.ftp.logout();
                        this.ftp.disconnect();
                   } catch (IOException f) {
                        // do nothing as file is already saved to server
                   }
              }
         }
    When I send file manually everything is OK, but when I use this code the width of file is cut.
    File on local disc have a 1080 charakters width, when transfer vie this code have 1002 charakters width.
    What can be wrong?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Problem with ftp

    When you download the file again, is it actually physically missing data? I've often seen that the size displayed in tool A and tool B can differ while the file is unchanged.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    moral is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Problem with ftp

    Quote Originally Posted by gimbal2 View Post
    When you download the file again, is it actually physically missing data? I've often seen that the size displayed in tool A and tool B can differ while the file is unchanged.
    I upload file to ftp server and the data is physically missing.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Problem with ftp

    Then I suspect an exception is thrown somewhere that you are not properly catching and logging and thus missing. I've always used commons-net for FTP transfers and have had no problems with it. The only problems that do exist are wonky network environments that cause transfers to fail unexpectedly.
    Last edited by gimbal2; 11-21-2013 at 01:01 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    moral is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Problem with ftp

    At this moment I resolve my problem like this:
    1. Copy the file and check every line is longer then 1002 characters.
    2. If line is longer then put the rest to next line.
    3. Then upolad file to FTP server.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Problem with ftp

    If that makes a difference the problem is somewhere else entirely; there are no lines in file transfers, only bytes.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Problem with ftp

    How are you reading these files at source and at destination?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    moral is offline Member
    Join Date
    Nov 2013
    Posts
    7
    Rep Power
    0

    Default Re: Problem with ftp

    I analize my code again i it's not a Apache commons-net fault. I run my program on z/OS and earlier in the code I use JZOS ZFile.getInputStream(); I think that's is real problem. Very thanks everyone for interest and help.

Similar Threads

  1. Problem with a Simple Histogram Problem
    By kathmandu in forum New To Java
    Replies: 12
    Last Post: 06-25-2013, 01:19 AM
  2. Replies: 0
    Last Post: 11-07-2012, 12:44 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •