Results 1 to 8 of 8
Thread: Problem with ftp
- 11-21-2013, 12:37 PM #1
Member
- Join Date
- Nov 2013
- Posts
- 7
- Rep Power
- 0
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 } } }
File on local disc have a 1080 charakters width, when transfer vie this code have 1002 charakters width.
What can be wrong?
- 11-21-2013, 01:35 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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
- 11-21-2013, 01:52 PM #3
Member
- Join Date
- Nov 2013
- Posts
- 7
- Rep Power
- 0
- 11-21-2013, 01:59 PM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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 02:01 PM.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 11-21-2013, 02:13 PM #5
Member
- Join Date
- Nov 2013
- Posts
- 7
- Rep Power
- 0
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.
- 11-21-2013, 02:22 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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
- 11-21-2013, 05:36 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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 **
- 11-22-2013, 08:09 AM #8
Member
- Join Date
- Nov 2013
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Problem with a Simple Histogram Problem
By kathmandu in forum New To JavaReplies: 12Last Post: 06-25-2013, 02:19 AM -
Delay between 2 same timings problem (Video of explanation of the problem inside)
By Lionlev in forum Advanced JavaReplies: 0Last Post: 11-07-2012, 01:44 PM -
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 04:43 AM -
Can anyone see the problem with my code? problem understanding switch (newbish)
By keith in forum New To JavaReplies: 9Last Post: 09-21-2010, 05:15 PM -
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 07:12 AM
Bookmarks