Created
May 27, 2017 14:20
-
-
Save hkarakose/8d551f72ded2033175ae62a8946f3dfc to your computer and use it in GitHub Desktop.
Upload File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>commons-net</groupId> | |
<artifactId>commons-net</artifactId> | |
<version>3.1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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