commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ari Fainchtein <artw...@lechido.com>
Subject Binary Files get corrupted with FTPClient
Date Fri, 07 Dec 2012 14:16:55 GMT
Hello,

I am trying to use the FTPClient to upload files and everything is working fine except that
the files arrive all garbled to the server.  I have tried with pdfs and jpegs and  in both
case the files are corrupted.

Any help would be appreciated.

  Here is the code I am using:
<br>

<code>
 try {
				
				
		    	
		    	String server = "XX.XX.XX.XX";;
				FTPClient ftpClient = new FTPClient();
				  
				ftpClient.connect(server);
				ftpClient.login("abc", "abc");
				
			    
			    
			    boolean error = false;
			    try {
			      int reply;
			      

			      
			      reply = ftpClient.getReplyCode();
			      
			      if(!FTPReply.isPositiveCompletion(reply)) {
			    	  ftpClient.disconnect();
			        System.err.println("FTP server refused connection.");
			        JOptionPane.showConfirmDialog(SendFileMonitorDialog.this, "Server refused connection",
"Error",JOptionPane.OK_OPTION);
			      }
			      ftpClient.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE);
				  ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
			      
			      
                  FileInputStream fileInputStream = new FileInputStream(selectedFile);
                  BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                  ProgressMonitorInputStream progressMonitorInputStream = new ProgressMonitorInputStream(SendFileMonitorDialog.this,
"Uploading " + selectedFile.getName(), bufferedInputStream);
                  
                  
                  ftpClient.makeDirectory( publicFolderName);
                  ftpClient.changeWorkingDirectory(publicFolderName);
                  
                  
                  ftpClient.storeFile(selectedFile.getName(), progressMonitorInputStream);
                  try {
					SwingUtilities.invokeAndWait( runner );
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                  progressMonitorInputStream.close(); 
			      ftpClient.logout();
			    } catch(IOException e) {
			      error = true;
			      e.printStackTrace();
			    } finally {
			      if(ftpClient.isConnected()) {
			        try {
			          ftpClient.disconnect();
			        } catch(IOException ioe) {
			          // do nothing
			        }
			      }
			      
			    }
			
				
	        }catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
</code>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message