[ https://issues.apache.org/jira/browse/NET-429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13180842#comment-13180842 ]
Allen Atamer commented on NET-429: ---------------------------------- Sorry about the sloppy cut and pastes. I lost track of which source produced which outputs as I was debugging. Nevertheless, it still doesn't work with the Commons Net code. I do have r/w access to the root folder and the /offline3 folder, so that isn't it. > 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: 1.4, 3.0.1 > Environment: jdk1.6.0_27 > Windows 7 Pro SP1 local machine > Uploading to a GoDaddy Linux shared hosting environment. File is created > with 0x604 permissions. > Reporter: Allen Atamer > Labels: bytes, ftp, storeFile, zero > > 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. When you get to the > storeFile(..) method, it waits for about 20 seconds before it returns the > error message shown to System.out. > 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) > 5. ftp.connect(server) and ftp.connect(server, 21) > Here's my code: > {noformat} > 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("/offline3/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); > } > {noformat} > Here's my System.out: > {noformat} > 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: C:/projects/TEMP/uga.html > {noformat} > More background: > FileZilla works on my machine > I've also tried the primitive Sun API, and it works perfectly: > {noformat} > try { > url = new > URL("ftp://username:passw...@ftp.myserver.com/offline3/uga.html;type=i"); > URLConnection urlc = url.openConnection(); > OutputStream os = urlc.getOutputStream(); // To upload > > String localPath = "C:/projects/TEMP/uga.html"; > InputStream bis = new BufferedInputStream(new > FileInputStream(localPath)); > > byte[] bstr = new byte[1024]; > while (bis.read(bstr) > 0) { > os.write(bstr); > } > } catch (MalformedURLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > {noformat} -- 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