

However, this method may not be necessary for some of storeXXX() methods. We should check return value of this method to ensure the upload is actually successful. It would return true if successfully completed, or false otherwise. boolean completePendingCommand(): This method should be called after file transfer finishes, to complete the transaction entirely.This method must be called before a file transfer starts. The default type is ASCII (plain text file), but it should be set to binary type in order to work with any files. boolean setFileType(int fileType): determines which file type, either FTP.ASCII_FILE_TYPE or FTP.BINARY_FILE_TYPE, is used for file transfer.Let the server names the remote file with a unique name (those methods which do not have a String parameter).ĭespite somewhat intricate of the storeXXX() methods, there are only two methods which are mostly used in practice, they are:īesides the storeXXX() methods, there are also two other ones need to be invoked before and after a file transfer:.Name the remote file explicitly (those methods which accept a String parameter called remote).The two ways above can be used in combination with: This can be useful if we want to show progress of the upload, by calculating how many bytes are transferred over total bytes needed.
#ANDROID FTP SERVER EXAMPLE CODE#
This type of methods is needed when we want to control how the bytes are transferred, by writing our own code for reading bytes from the local file and write these bytes to the remote file through the OutputStream object. Store files by writing to an OutputStream of the connection (those methods which return an OutputStream).This type of methods can be used when we don’t care how the bytes are transferred from the local file to the remote one, just let the system done the ins and outs. Store files by providing an InputStream of the local file (those methods which have an InputStream as a parameter).Sounds too much? What is the difference among these methods? When to use which one? Well, they can be categorized by the following means: OutputStream storeUniqueFileStream(String remote).boolean storeUniqueFile(String remote, InputStream local).boolean storeUniqueFile( InputStream local).OutputStream storeFileStream(String remote).boolean storeFile(String remote, InputStream local).Apache Commons Net API for uploading files by FTP protocol The FTPClient class provides six store XXX()methods for transferring a local file to a remote server via FTP protocol: Apache Commons Net API for uploading files by FTP protocolġ.It has simple and comprehensive API that makes coding with upload files to FTP server with ease. To write Java code that uploads a file from local computer to a remote FTP server, the Apache Commons Net API is a preferred choice of developers.
