Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void upload(String domain, String user1, String password, String path, String fileName) {
- String server = domain;
- int port = 21;
- String user = user1;
- String pass = password;
- FTPClient ftpClient = new FTPClient();
- try {
- try {
- ftpClient.connect(server, port);
- ftpClient.login(user, pass);
- ftpClient.enterLocalPassiveMode();
- } catch (Exception e) {
- }
- ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
- // APPROACH #1: uploads first file using an InputStream
- File firstLocalFile = new File(path);
- String firstRemoteFile = fileName;
- InputStream inputStream = new FileInputStream(firstLocalFile);
- System.out.println("Start uploading first file");
- boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
- inputStream.close();
- if (done) {
- System.out.println("The first file is uploaded successfully.");
- }
- } catch (IOException ex) {
- System.out.println("Error: " + ex.getMessage());
- ex.printStackTrace();
- } finally {
- try {
- if (ftpClient.isConnected()) {
- ftpClient.logout();
- ftpClient.disconnect();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement