Las Vegas Posted January 22, 2018 at 03:52 PM Report #609043 Posted January 22, 2018 at 03:52 PM Boas comunidade, Necessitava de uma ajuda, se possível, que não estou a conseguir. Quando faço um upload para a minha pasta de que se encontra no ftp server, antes de o fazer gostava de verificar se o nome de um documento já existe. Para evitar o overwrite. Desde já obrigado a todos
Las Vegas Posted January 22, 2018 at 04:55 PM Author Report #609044 Posted January 22, 2018 at 04:55 PM (edited) Já consegui... deixo aqui a solução para quem tiver a mesma duvida FTPClient ftp = new FTPClient(); int port = 21; ftp.connect("ftp server", port); ftp.login("user","pass"); ftp.enterLocalPassiveMode(); ftp.setFileType(FTP.BINARY_FILE_TYPE); File fileName = save.getSelectedFile(); String localFile = "/" + fileName.getName(); FileInputStream input = new FileInputStream(fileName); System.out.println("total " + input.available()); FTPFile files = ftp.mlistFile(localFile); if(files != null){ JOptionPane.showMessageDialog(null, "Já existe um documento com o mesmo nome."); }else{ boolean out = ftp.storeFile(localFile, input); input.close(); if(out){ System.out.println("Sucess"); } } Edited January 22, 2018 at 04:55 PM by Las Vegas
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now