Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.5k views
in Java FTP by
I am testing on edtftpj 1.5.2 and try to send an excel file from one workstation to another workstation.
However, I found that the excel file in the destination workstation has 1 byte more than that of the orginal excel file and therefore the excel file is corrupted.
The code is shown as below:
public void ftpSendFile (String file_name, String user_id, String source_path) {      
   FTPClient ftp = null;
   String[] ls_directory_content = null;
   boolean ls_directory_exist = false;
      
   try {
      ftp = new FTPClient();
      ftp.setRemoteHost(ftp_host);      
      ftp.connect();      
      ftp.login(ftp_user, ftp_pwd);   
      
      ftp.setConnectMode(FTPConnectMode.PASV);
      ftp.setType(FTPTransferType.ASCII);      

      ls_directory_content = ftp.dir();
      int i = 0;
      for (i=0; i<ls_directory_content.length; i++) {
         if (ls_directory_content[i].compareTo(user_id.trim().toUpperCase()) == 0) {
         ls_directory_exist = true;
            }
         }
         if (!ls_directory_exist) {
            ftp.mkdir(user_id.trim().toUpperCase());   
         }

         ftp.chdir(user_id.trim().toUpperCase());
         ftp.put(source_path + file_name, file_name);
         
         ftp.quit();
   } catch (Exception e) {
         log.log("Test FTP: Exception: " + e.getMessage());
   }
   }



Here is the message popup when I open the excel file in destination workstation:
---------------------------------------------------------------------
Microsoft Office Excel File Repair Log

Errors were detected in file 'C:\TEST\test.xls'
The following is a list of repairs:

Damage to the file was so extensive that repairs were not possible. Excel attempted to recover your formulas and values, but some data may have been lost or corrupted.

1 Answer

0 votes
by (162k points)
You need to send it in binary mode, not ASCII - it isn't a text file.

Categories

...