commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Cole" <sc...@camsbycbs.com>
Subject RE: FTPClient hangs when downloading large files
Date Wed, 16 Feb 2011 12:59:28 GMT
Try it with some other FTP client software. If it doesn't work, then the
problem isn't in your java class.


-----Original Message-----
From: Cysneros, Nelson A CIV SPAWARSYSCEN-PACIFIC, 56540
[mailto:nelson.cysneros@navy.mil] 
Sent: Tuesday, February 15, 2011 4:50 PM
To: user@commons.apache.org
Subject: FTPClient hangs when downloading large files



I'm using the net-commons v2.2 FTPClient to download files from a server
and it works great for files less then 250MB, but hangs with larger
files.
Wondering if there is anything I can do to get around this issue.  I'm
downloading files up to 500MB in size.  
Thanks in advance.

Here is my source code:
------------------------------------------------------------------------

		FTPClient ftpClient = new FTPClient();
		File file = null;

		//
////////////////////////////////////////////////////////////////////
		// Grab all files from the FTP server and place them in
the specified
		// folder for processing.
	
////////////////////////////////////////////////////////////////////////

			// Log on to FTP server
			try {
				// FTP Server
				ftpClient.enterLocalPassiveMode();
				ftpClient.connect(ftpServer);

				// After connection attempt, you should
check the reply code to verify
				// success.
				int reply = ftpClient.getReplyCode();
				if
(!FTPReply.isPositiveCompletion(reply))
				{
					ftpClient.disconnect();
					logger.error("FTP server refused
connection.");
					System.exit(1);
				}
	
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
				ftpClient.login(m_sFTPCredUN,
m_sFTPCredPW);

			} catch (java.net.ConnectException ex1) {

				logger.info(ex1.getMessage());
				System.out.print("-----FTP Connection
problem: "+ ftpServer+"\n");
				return;
			}catch (Exception ex1) {

				logger.info(ex1.getMessage());
				System.out.print("-----FTP Connection
problem: "+ftpServer+"\n");
				return;
			}
			
			//Download files
			FileOutputStream fos=null;
			try {
				// List the files in the directory
				FTPFile[] files =
ftpClient.listFiles(ftpPath);
				logger.info("Number of files in dir: " +
files.length);
				for (int i = 0; i < files.length; i++) {
					String fileName =
files[i].getName();
				
					// ////////////////
					// Get Files
					// ////////////////
					logger.info("Getting file: " +
fileName);
					file = new
File(m_sInputRapierPath + File.separator
							+
files[i].getName());
					fos = new
FileOutputStream(file);

					ftpClient.retrieveFile(ftpPath +
"/" + files[i].getName(),fos); //Hangs here
					logger.info("File transfer
complete");
					fos.close();

					}

				

			} catch
(org.apache.commons.net.io.CopyStreamException e) {
				logger.info("FTP FETCH PROBLEM(1): " +
e.getMessage());
				//System.out.println("FTP FETCH
PROBLEM(1): " + e.getMessage());
				try {
					if (file != null){
						fos.close();
						file.delete();
					}
				}//try
				catch(IOException ex){
					logger.info("FTP Problem
occured(4) : " + ex.getMessage());
				}//catch

			} catch (Exception ex) {
				logger.info("FTP FETCH PROBLEM(3): " +
ex.getMessage());
				//System.out.println("FTP FETCH
PROBLEM(3): " + e.getMessage());
				try {
					if (file != null){
						fos.close();
						file.delete();
					}
				}//try
				catch(IOException ex1){
					logger.info("FTP Problem
occured(4) : " + ex1.getMessage());
				}//catch
			} finally {
				try {
					if (file != null){
						
						// Logout from the FTP
Server and disconnect
						ftpClient.logout();
	
if(ftpClient.isConnected())
	
ftpClient.disconnect();
					}
				}//try
				catch(IOException ex){
					logger.info("FTP Problem
occured(4) : " + ex.getMessage());
				}//catch
			}//finally

		}// if



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message