Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.2k views
in Java FTP by
When I upload zip files, they're always corrupted, I'm using binary mode. Is there something else I need to do?

4 Answers

0 votes
by (162k points)
No, this shouldn't happen. Most likely, either they are corrupt before you upload or binary mode isn't being used.

Post a code snippet that isolates the problem & we'll take a look. Also post a log file that shows the FTP commands.

When I upload zip files, they're always corrupted, I'm using binary mode. Is there something else I need to do?
0 votes
by
I make my connection in the constructor, could that cause a problem?

Here is my constructor (with connection) and the simple, upload call.

The files all appear the be fine before they are uploaded.
----------------------------------------------------------------------------------
/**
* Instantiate the FTP and connect
* @param host
* @param username
* @param password
*/
public FTP(String host, String username, String password){
this.host = host;
this.username = username;
this.password = password;
try{
client = new FTPClient(host);

print("Username: " + username);
print("Password: " + password);
client.login(username, password);

client.setConnectMode(FTPConnectMode.PASV);
client.setType(FTPTransferType.BINARY);


print("Logged into server");

// print("Moved to Backups Directory");
}
catch(Exception e){
System.err.println("Could not connect to FTP server: " + e);
e.printStackTrace();
}
}

/**
* upload this file to the given ftp server
* @param file
*/
public void upload(File file){
try{
client.put(file.getAbsolutePath(), file.getName());
}
catch(Exception e){
System.err.println("Could not upload file to FTP server: " + e);
e.printStackTrace();
}
}
----------------------------------------------------------------------------------
And here's the server messages:
----------------------------------------------------------------------------------
2004-9-23 11:15:57- (not logged in) (68.110.128.81) > 220 Welcome to WinFtp Server.
2004-9-23 11:15:57- (not logged in) (68.110.128.81) > USER BRENTBACKUPS
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 331 Password required for brentbackups
2004-9-23 11:15:57- brentbackups (68.110.128.81) > PASS **************
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 230 Logged on
2004-9-23 11:15:57- brentbackups (68.110.128.81) > TYPE I
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 200 Type set to I
2004-9-23 11:15:57- brentbackups (68.110.128.81) > SYST
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 215 UNIX Type: L8
2004-9-23 11:15:57- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,235)
2004-9-23 11:15:57- brentbackups (68.110.128.81) > LIST .
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:57- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,236)
2004-9-23 11:15:57- brentbackups (68.110.128.81) > NLST
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:57- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:58- brentbackups (68.110.128.81) > DELE C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@VerizonBill.MDI.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 250 File deleted successfully
2004-9-23 11:15:58- brentbackups (68.110.128.81) > DELE C!@DocumentsandSettings@Dad@MyDocuments@Financial@Travel@airline.txt.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 250 File deleted successfully
2004-9-23 11:15:58- brentbackups (68.110.128.81) > DELE C!@DocumentsandSettings@Dad@MyDocuments@Financial@Travel@December03VegasItinerary.html.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 250 File deleted successfully
2004-9-23 11:15:58- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,237)
2004-9-23 11:15:58- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@Travel@December03VegasItinerary.html.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:58- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,238)
2004-9-23 11:15:58- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@Travel@airline.txt.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:58- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,239)
2004-9-23 11:15:58- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@VerizonBill.MDI.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:58- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,240)
2004-9-23 11:15:58- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@QuarterlyHomeownersAssociationFee.MDI.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:58- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,241)
2004-9-23 11:15:58- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@MBNAPayment.MDI.zip
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:58- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:59- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,242)
2004-9-23 11:15:59- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@JiglooLicense.MDI.zip
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:59- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 227 Entering Passive Mode (68,110,128,81,17,243)
2004-9-23 11:15:59- brentbackups (68.110.128.81) > STOR C!@DocumentsandSettings@Dad@MyDocuments@Financial@September04BillReceipts@CoxBillPayment.doc.zip
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 150 Data connection accepted; transfer starting.
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 226 Transfer ok
2004-9-23 11:15:59- brentbackups (68.110.128.81) > PASV
2004-9-23 11:15:59- brentbackups (68.110.128.81) > 227 Ent
0 votes
by (162k points)
As a workaround, call

client.setType(FTPTransferType.BINARY);

in the method upload() just before you do the transfer.

Does that work?

I make my connection in the constructor, could that cause a problem?

Here is my constructor (with connection) and the simple, upload call.

0 votes
by
Tried that, same thing... I've tested a bunch of times that they're alright before transfer. And they're just a bit corrupted after transfer, text files look mostly the same, but with a few odd chars placed near the end, but not at the very end.

Also, it gives me this on disconnect: Think it's not closing out the streams or something?

------------------------------------------------------------
com.enterprisedt.net.ftp.FTPException: Bye.
at com.enterprisedt.net.ftp.FTPControlSocket.validateReply(FTPControlSocket.java:729)
at com.enterprisedt.net.ftp.FTPClient.quit(FTPClient.java:2127)
at FTP.disconnect(FTP.java:189)
at RemoteBackup$1.construct(RemoteBackup.java:109)
at SwingWorker$2.run(SwingWorker.java:106)
at java.lang.Thread.run(Unknown Source)
------------------------------------------------------------

Categories

...