Skip to content

Instantly share code, notes, and snippets.

@hkarakose
Created May 27, 2017 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkarakose/8d551f72ded2033175ae62a8946f3dfc to your computer and use it in GitHub Desktop.
Save hkarakose/8d551f72ded2033175ae62a8946f3dfc to your computer and use it in GitHub Desktop.
Upload File
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.1</version>
</dependency>
public static boolean upload(String url, String username, String password, File file) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect(url);
client.login(username, password);
fis = new FileInputStream(file);
// Store file on server and logout
boolean uploaded = client.storeFile(file.getName(), fis);
client.logout();
return uploaded;
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment