List of usage examples for org.apache.commons.net.ftp FTP COMPRESSED_TRANSFER_MODE
int COMPRESSED_TRANSFER_MODE
To view the source code for org.apache.commons.net.ftp FTP COMPRESSED_TRANSFER_MODE.
Click Source Link
From source file:com.google.android.exoplayer.upstream.FtpDataSource.java
@Override public long open(DataSpec dataSpec) throws FtpDataSourceException { this.dataSpec = dataSpec; String host = dataSpec.uri.getHost(); int port = dataSpec.uri.getPort(); if (port <= 0) port = FTP.DEFAULT_PORT;//from w w w . j a v a 2s . c om String filePath = dataSpec.uri.getPath(); String userInfo = dataSpec.uri.getUserInfo(); Log.i("ftp", "fpt login:" + dataSpec.uri.toString() + " " + dataSpec.position); String user = "anonymous", pass = ""; if (userInfo != null) { StringTokenizer tok = new StringTokenizer(userInfo, ":@"); if (tok.countTokens() > 0) { user = tok.nextToken(); if (tok.hasMoreTokens()) pass = tok.nextToken(); } } try { long start_time = System.currentTimeMillis(); ftpClient.connect(host, port); isConnect = FTPReply.isPositiveCompletion(ftpClient.getReplyCode()); if (!isConnect) throw new FtpDataSourceException("connect failed."); Log.i("ftp", "ftp connect use:" + (System.currentTimeMillis() - start_time)); isLogin = ftpClient.login(user, pass); Log.i("ftp", "ftp login use:" + (System.currentTimeMillis() - start_time)); Log.i("ftp", "fpt login:" + user + ":" + pass + "@" + host + ":" + port + " - " + isLogin); if (!isLogin) throw new FtpDataSourceException("login failed."); fileSize = getFileSize(ftpClient, filePath); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE); ftpClient.setRestartOffset(dataSpec.position); stream = ftpClient.retrieveFileStream(filePath); bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? fileSize - dataSpec.position : dataSpec.length; } catch (IOException e) { throw new FtpDataSourceException(e); } opened = true; if (listener != null) { listener.onTransferStart(); } return bytesRemaining; }
From source file:fr.lille1.car.burihabwa.rest.utils.FTPAdapterImpl.java
public void stor(String path, InputStream received) throws IOException { if (path == null) { throw new IllegalArgumentException("path argument cannot be null!"); }/* w ww .j av a 2 s.c o m*/ if (received == null) { throw new IllegalArgumentException("received argument cannot be null!"); } if (!this.client.isConnected()) { authenticate(); } String parentDirectory = getParentDirectory(path); String file = getFile(path); this.client.changeWorkingDirectory(parentDirectory); this.client.setBufferSize(4096); this.client.setFileType(FTP.BINARY_FILE_TYPE); this.client.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE); boolean storeFile = this.client.storeFile(file, received); if (!storeFile) { Logger.getLogger(FTPAdapterImpl.class.getName()).log(Level.WARNING, this.client.getReplyString()); throw new IOException(this.client.getReplyString()); } received.close(); close(); }
From source file:se.natusoft.maven.plugin.ftp.FTPMojo.java
/** * Executes the mojo./*from ww w .ja v a2s. c o m*/ * * @throws MojoExecutionException */ public void execute() throws MojoExecutionException { FTPClient ftpClient = new FTPClient(); try { ftpClient.connect(this.targetHost, this.targetPort); if (!ftpClient.login(this.userName, this.password)) { throw new MojoExecutionException("Failed to login user '" + this.userName + "'!"); } this.getLog() .info("FTP: Connected to '" + this.targetHost + ":" + this.targetPort + "':" + this.targetPath); ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE); ftpClient.setBufferSize(1024 * 60); SourcePaths sourcePaths = new SourcePaths(new File(this.baseDir), this.files); this.getLog().info("Files to upload: " + sourcePaths.getSourceFiles().size()); int fileNo = 0; for (File transferFile : sourcePaths.getSourceFiles()) { String relPath = this.targetPath + transferFile.getParentFile().getAbsolutePath().substring(this.baseDir.length()); boolean havePath = ftpClient.changeWorkingDirectory(relPath); if (!havePath) { if (!mkdir(ftpClient, relPath)) { throw new MojoExecutionException("Failed to create directory '" + relPath + "'!"); } if (!ftpClient.changeWorkingDirectory(relPath)) { throw new MojoExecutionException( "Failed to change to '" + relPath + "' after its been created OK!"); } } FileInputStream sendFileStream = new FileInputStream(transferFile); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.storeFile(transferFile.getName(), sendFileStream); sendFileStream.close(); this.getLog().info( "Transferred [" + ++fileNo + "]: " + relPath + File.separator + transferFile.getName()); } this.getLog().info("All files transferred!"); } catch (IOException ioe) { throw new MojoExecutionException(ioe.getMessage(), ioe); } finally { try { ftpClient.disconnect(); } catch (IOException ioe) { this.getLog().error("Failed to disconnect from FTP site! [" + ioe.getMessage() + "]", ioe); } } }