FTPClient storeFile method creates a file of 0 bytes
----------------------------------------------------

                 Key: NET-429
                 URL: https://issues.apache.org/jira/browse/NET-429
             Project: Commons Net
          Issue Type: Bug
          Components: FTP
    Affects Versions: 3.0.1, 1.4
         Environment: jdk1.6.0_27
Windows 7 Pro SP1
            Reporter: Allen Atamer


Using the FTPClient object in commons net the way it is shown in the Javadoc 
results in a file that is 0 bytes on the remote host.

I've tried a number of different things

1. commons-net version 3.0.1 (supposedly had the bug fix for this, but didn't 
work for me)
2. [boolean] storeFile (String, InputStream)
3. [OutputStream] storeFile (String)
4. commons-net version 1.4 (still no dice)

Here's my code:
{quote}
                boolean error = false;
                FTPClient ftp = new FTPClient();
                InputStream localStream = null;
                try {
                        int reply;
                        String server = "ftp.myserver.com";
                        ftp.connect(server, 21);
                        System.out.println("Connected to " + server + ".");
                        System.out.print(ftp.getReplyString());

                        // After connection attempt, you should check the reply 
code to
                        // verify
                        // success.
                        reply = ftp.getReplyCode();

                        if (!FTPReply.isPositiveCompletion(reply)) {
                                ftp.disconnect();
                                System.err.println("FTP server refused 
connection.");
                                System.exit(1);
                        }
                        boolean wasSuccessful = ftp.login("user", "password");
                        if (!wasSuccessful) {
                                System.err.println("Login unsuccessful");
                                System.exit(1);
                        }
                        
                        System.out.println("login successful");
                        String localPath="C:/projects/TEMP/uga.html";
                        File localFile = new File(localPath);
                        
                        if (localFile.exists()) {
                                localStream = new BufferedInputStream(new 
FileInputStream(localPath));
                                wasSuccessful = ftp.storeFile("uga.html", 
localStream);
                                if (!wasSuccessful) {
                                        System.err.println("could not store 
file: " + localPath);
                                        System.exit(1);
                                } else {
                                        System.out.println("Successfully saved 
file!");
                                }
                        }

                        
                        // transfer files
                        ftp.logout();
                } catch (IOException e) {
                        error = true;
                        e.printStackTrace();
                } finally {
                        if (ftp.isConnected()) {
                                try {
                                        ftp.disconnect();
                                } catch (IOException ioe) {
                                        // do nothing
                                }
                        }
                        if (localStream != null) {
                                try {
                                        localStream.close();
                                } catch (IOException e) {
                                }
                        }
                        System.exit(error ? 1 : 0);
        }
{quote}

Here's my System.out:

{quote}
Connected to ftp.harmari.com.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 16 of 500 allowed.
220-Local time is now 05:59. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
login successful
could not store file: 2482049866.html
{quote}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to