| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package net.sf.webphotos.gui.util; |
| 17 | |
|
| 18 | |
import java.awt.*; |
| 19 | |
import java.awt.event.*; |
| 20 | |
import java.io.*; |
| 21 | |
import javax.swing.*; |
| 22 | |
import net.sf.webphotos.BancoImagem; |
| 23 | |
import net.sf.webphotos.sync.FTP.SyncAdapter; |
| 24 | |
import net.sf.webphotos.sync.Sync; |
| 25 | |
import net.sf.webphotos.sync.SyncEvent; |
| 26 | |
import net.sf.webphotos.sync.SyncException; |
| 27 | |
import net.sf.webphotos.util.ApplicationContextResource; |
| 28 | |
import net.sf.webphotos.util.Util; |
| 29 | |
import net.sf.webphotos.util.legacy.Arquivo; |
| 30 | |
import net.sf.webphotos.util.legacy.Modal; |
| 31 | |
import org.apache.commons.net.ftp.FTPFile; |
| 32 | |
import org.apache.commons.net.io.CopyStreamAdapter; |
| 33 | |
import org.apache.commons.net.io.CopyStreamException; |
| 34 | |
import org.apache.log4j.Logger; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public class FtpClient extends JFrame implements Runnable { |
| 41 | |
|
| 42 | |
private static final int ONE_SECOND = 1000; |
| 43 | 0 | private static final Logger log = Logger.getLogger(FtpClient.class); |
| 44 | 0 | private String ftpRoot = Util.getProperty("FTPRoot"); |
| 45 | 0 | private static File albunsRoot = Util.getAlbunsRoot(); |
| 46 | |
private Container cp; |
| 47 | |
private JScrollPane scrTabela; |
| 48 | |
private JTable tabela; |
| 49 | 0 | private JTextArea txtLog = new JTextArea(); |
| 50 | 0 | private JScrollPane scrLog = new JScrollPane(txtLog); |
| 51 | 0 | private JProgressBar barra = new JProgressBar(0, 100); |
| 52 | 0 | private JProgressBar barraArquivoAtual = new JProgressBar(0, 100); |
| 53 | 0 | private JLabel lblServidor = new JLabel(); |
| 54 | 0 | private JLabel lblArquivos = new JLabel("", JLabel.RIGHT); |
| 55 | 0 | private JLabel lblKbytes = new JLabel("0 Kb"); |
| 56 | 0 | private JLabel lblKbytesArquivoAtual = new JLabel("0 Kb"); |
| 57 | 0 | private JButton btFechar = new JButton("fechar"); |
| 58 | |
private FTPTabelModel modeloTabela; |
| 59 | |
private Modal modal; |
| 60 | |
private Sync ftp; |
| 61 | |
private int reply; |
| 62 | |
private int retry; |
| 63 | |
private String usuario; |
| 64 | |
private String ftpHost; |
| 65 | |
private int ftpPort; |
| 66 | |
private char[] senha; |
| 67 | 0 | private long totalBytes = 0; |
| 68 | 0 | private long transmitido = 0; |
| 69 | 0 | private FTPFile remoteFiles[] = null; |
| 70 | 0 | private FTPFile remoteFile = null; |
| 71 | |
|
| 72 | |
private boolean enviarAltaResolucao; |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | 0 | public FtpClient() { |
| 81 | 0 | cp = getContentPane(); |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | 0 | retry = 3; |
| 86 | |
try { |
| 87 | |
|
| 88 | 0 | ftp = (Sync) ApplicationContextResource.getBean("syncObject"); |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | 0 | ftp.setSyncFolder(ftpRoot); |
| 93 | 0 | enviarAltaResolucao = ftp.isEnviarAltaResolucao(); |
| 94 | 0 | ftp.loadSyncCache(); |
| 95 | 0 | } catch (Exception ex) { |
| 96 | 0 | Util.log("[FtpClient.run]/ERRO: Inexperado."); |
| 97 | 0 | log.error(ex); |
| 98 | 0 | System.exit(1); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
|
| 102 | 0 | if (enviarAltaResolucao == false) { |
| 103 | 0 | this.setTitle("Transmissão FTP - Sem Enviar Originais"); |
| 104 | |
} else { |
| 105 | 0 | this.setTitle("Transmissão FTP - Enviando Originais"); |
| 106 | |
} |
| 107 | 0 | txtLog.setFont(new Font("courier", Font.PLAIN, 11)); |
| 108 | 0 | Util.setLoggingTextArea(txtLog); |
| 109 | 0 | cp.setLayout(null); |
| 110 | |
|
| 111 | 0 | cp.add(lblArquivos); |
| 112 | 0 | lblArquivos.setBounds(348, 3, 60, 18); |
| 113 | |
|
| 114 | 0 | cp.add(lblServidor); |
| 115 | 0 | lblServidor.setBounds(8, 3, 340, 18); |
| 116 | |
|
| 117 | 0 | txtLog.setWrapStyleWord(true); |
| 118 | 0 | txtLog.setLineWrap(true); |
| 119 | 0 | cp.add(scrLog); |
| 120 | 0 | scrLog.setBounds(8, 127, 400, 70); |
| 121 | |
|
| 122 | 0 | modeloTabela = new FTPTabelModel(ftp.getListaArquivos()); |
| 123 | 0 | tabela = new JTable(modeloTabela); |
| 124 | |
|
| 125 | 0 | cp.add(tabela); |
| 126 | 0 | scrTabela = new JScrollPane(tabela); |
| 127 | 0 | cp.add(scrTabela); |
| 128 | 0 | scrTabela.setBounds(8, 20, 400, 100); |
| 129 | 0 | cp.validate(); |
| 130 | |
|
| 131 | |
|
| 132 | 0 | cp.add(barraArquivoAtual); |
| 133 | 0 | barraArquivoAtual.setStringPainted(true); |
| 134 | 0 | barraArquivoAtual.setBounds(8, 235, 234, 18); |
| 135 | 0 | barraArquivoAtual.setToolTipText("Progresso do arquivo atual"); |
| 136 | |
|
| 137 | 0 | cp.add(lblKbytesArquivoAtual); |
| 138 | 0 | lblKbytesArquivoAtual.setBounds(246, 235, 58, 18); |
| 139 | |
|
| 140 | |
|
| 141 | 0 | cp.add(barra); |
| 142 | 0 | barra.setStringPainted(true); |
| 143 | 0 | barra.setBounds(8, 205, 234, 18); |
| 144 | 0 | barra.setToolTipText("Progresso total"); |
| 145 | |
|
| 146 | 0 | cp.add(lblKbytes); |
| 147 | 0 | lblKbytes.setBounds(246, 205, 58, 18); |
| 148 | |
|
| 149 | 0 | cp.add(btFechar); |
| 150 | 0 | btFechar.setBounds(308, 204, 100, 20); |
| 151 | 0 | btFechar.setEnabled(false); |
| 152 | |
|
| 153 | 0 | this.setSize(420, 300); |
| 154 | 0 | this.setResizable(false); |
| 155 | 0 | this.setLocationRelativeTo(null); |
| 156 | 0 | this.setDefaultCloseOperation(FtpClient.DO_NOTHING_ON_CLOSE); |
| 157 | 0 | this.getContentPane().repaint(); |
| 158 | 0 | this.setVisible(true); |
| 159 | |
|
| 160 | 0 | modal = new Modal(this); |
| 161 | 0 | this.addWindowFocusListener(modal); |
| 162 | |
|
| 163 | |
|
| 164 | 0 | btFechar.addMouseListener(new MouseAdapter() { |
| 165 | |
@Override |
| 166 | |
public void mouseClicked(MouseEvent e) { |
| 167 | 0 | exit(); |
| 168 | 0 | } |
| 169 | |
}); |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
if (1 == 2) { |
| 174 | |
addWindowListener(new java.awt.event.WindowAdapter() { |
| 175 | |
@Override |
| 176 | |
public void windowClosing(java.awt.event.WindowEvent evt) { |
| 177 | |
exit(); |
| 178 | |
} |
| 179 | |
}); |
| 180 | |
} |
| 181 | |
|
| 182 | 0 | ftp.setSyncListener(new SyncAdapter() { |
| 183 | |
@Override |
| 184 | |
public void connected(SyncEvent e) { |
| 185 | 0 | lblServidor.setText(ftpHost + ":" + ftpPort + " / usuário: " + usuario); |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
@Override |
| 189 | |
public void logonStarted(SyncEvent event) { |
| 190 | |
|
| 191 | 0 | if (!event.isRetrying()) { |
| 192 | 0 | if (BancoImagem.getBancoImagem().getUserFTP() != null) { |
| 193 | |
|
| 194 | 0 | usuario = BancoImagem.getBancoImagem().getUserFTP(); |
| 195 | 0 | senha = BancoImagem.getBancoImagem().getPasswordFTP(); |
| 196 | 0 | } else if (BancoImagem.getBancoImagem().getUser() != null) { |
| 197 | |
|
| 198 | 0 | usuario = BancoImagem.getBancoImagem().getUser(); |
| 199 | 0 | senha = BancoImagem.getBancoImagem().getPassword(); |
| 200 | |
} else { |
| 201 | 0 | showLogonDialog(); |
| 202 | |
} |
| 203 | |
} else { |
| 204 | 0 | showLogonDialog(); |
| 205 | |
} |
| 206 | 0 | ftp.setUsuario(usuario); |
| 207 | 0 | ftp.setSenha(senha); |
| 208 | 0 | } |
| 209 | |
|
| 210 | |
@Override |
| 211 | |
public void disconnected(SyncEvent e) { |
| 212 | |
|
| 213 | |
|
| 214 | 0 | btFechar.setEnabled(true); |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
private void showLogonDialog() { |
| 218 | |
|
| 219 | 0 | Login l = new Login("FTP " + ftpHost); |
| 220 | 0 | removeWindowFocusListener(modal); |
| 221 | 0 | l.show(); |
| 222 | 0 | addWindowFocusListener(modal); |
| 223 | 0 | usuario = l.getUser(); |
| 224 | 0 | senha = l.getPassword(); |
| 225 | 0 | } |
| 226 | |
}); |
| 227 | |
|
| 228 | 0 | ftp.setCopyStreamListener(new CopyStreamAdapter() { |
| 229 | |
@Override |
| 230 | |
public void bytesTransferred(long totalBytesTransferred, |
| 231 | |
int bytesTransferred, |
| 232 | |
long streamSize) { |
| 233 | 0 | barraArquivoAtual.setValue((int) totalBytesTransferred); |
| 234 | 0 | lblKbytesArquivoAtual.setText(Math.round((float) totalBytesTransferred / 1024) + " Kb"); |
| 235 | 0 | } |
| 236 | |
}); |
| 237 | 0 | } |
| 238 | |
|
| 239 | |
private void exit() { |
| 240 | |
|
| 241 | |
|
| 242 | 0 | dispose(); |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
@Override |
| 253 | |
public void run() { |
| 254 | |
|
| 255 | |
String acao; |
| 256 | |
String albumID; |
| 257 | |
String arquivo; |
| 258 | |
long tamanho; |
| 259 | |
|
| 260 | |
String arqOrigem; |
| 261 | |
String arqDestino; |
| 262 | |
|
| 263 | 0 | Object streamOrigem = null; |
| 264 | 0 | Object streamDestino = null; |
| 265 | |
|
| 266 | 0 | String ultimoID = ""; |
| 267 | 0 | int i, j = 0; |
| 268 | |
|
| 269 | 0 | String diretorioDownload = null; |
| 270 | |
|
| 271 | 0 | ftp.loadSyncCache(); |
| 272 | 0 | modeloTabela.refresh(ftp.getListaArquivos()); |
| 273 | 0 | modeloTabela.fireTableDataChanged(); |
| 274 | |
|
| 275 | |
|
| 276 | 0 | if (tabela.getRowCount() == 0) { |
| 277 | 0 | ftp.disconnect("Não há comandos ftp"); |
| 278 | 0 | return; |
| 279 | |
} |
| 280 | |
|
| 281 | |
|
| 282 | 0 | if (!ftp.connect()) { |
| 283 | 0 | return; |
| 284 | |
} |
| 285 | 0 | preProcessBatch(); |
| 286 | 0 | modeloTabela.refresh(ftp.getListaArquivos()); |
| 287 | 0 | modeloTabela.fireTableDataChanged(); |
| 288 | 0 | barra.setMaximum(Integer.parseInt(Long.toString(totalBytes))); |
| 289 | |
|
| 290 | |
|
| 291 | 0 | for (i = 0; i < tabela.getRowCount(); i++) { |
| 292 | |
|
| 293 | 0 | lblArquivos.setText(i + 1 + " / " + tabela.getRowCount()); |
| 294 | 0 | tabela.setRowSelectionInterval(i, i); |
| 295 | 0 | tabela.scrollRectToVisible(tabela.getCellRect(i + 1, 0, true)); |
| 296 | 0 | tabela.repaint(); |
| 297 | 0 | acao = tabela.getValueAt(i, 1).toString(); |
| 298 | 0 | albumID = tabela.getValueAt(i, 2).toString(); |
| 299 | 0 | arquivo = tabela.getValueAt(i, 4).toString(); |
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | 0 | if (!ultimoID.equals(albumID)) { |
| 304 | 0 | Util.log("Mudando para o diretório " + albumID); |
| 305 | |
try { |
| 306 | 0 | ftp.cd(albumID); |
| 307 | 0 | remoteFiles = ftp.listFiles(); |
| 308 | 0 | diretorioDownload = null; |
| 309 | 0 | } catch (IOException ioE) { |
| 310 | 0 | Util.log("[FtpClient.run]/ERRO: comando não foi aceito ao listar o diretório " + albumID + " desconectando"); |
| 311 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 312 | 0 | } catch (SyncException se) { |
| 313 | 0 | Util.log(se.getMessage()); |
| 314 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 315 | 0 | } |
| 316 | |
} |
| 317 | |
|
| 318 | |
|
| 319 | 0 | if (acao.equals("enviar")) { |
| 320 | 0 | if (diretorioDownload == null) { |
| 321 | 0 | diretorioDownload = albunsRoot.getAbsolutePath() + File.separator + albumID; |
| 322 | |
} |
| 323 | 0 | arqOrigem = diretorioDownload + File.separator + arquivo; |
| 324 | 0 | Util.out.println(arqOrigem + " -> " + arquivo); |
| 325 | |
try { |
| 326 | 0 | streamOrigem = new FileInputStream(arqOrigem); |
| 327 | 0 | streamDestino = new BufferedOutputStream(ftp.storeFileStream(arquivo), ftp.getBufferSize()); |
| 328 | 0 | this.transfereArquivo((InputStream) streamOrigem, (OutputStream) streamDestino, Long.parseLong(tabela.getValueAt(i, 5).toString())); |
| 329 | 0 | tabela.setValueAt("ok", i, 0); |
| 330 | 0 | } catch (FileNotFoundException ioE) { |
| 331 | 0 | Util.log("[FtpClient.run]/AVISO: " + arqOrigem + " não foi encontrado."); |
| 332 | 0 | tabela.setValueAt("ok - ne", i, 0); |
| 333 | 0 | } catch (IOException ioE) { |
| 334 | 0 | Util.log("[FtpClient.run]/ERRO: erro na transmissão de " + arqOrigem); |
| 335 | 0 | ioE.printStackTrace(Util.out); |
| 336 | 0 | tabela.setValueAt("erro", i, 0); |
| 337 | 0 | } catch (Exception e) { |
| 338 | 0 | Util.err.println("Erro inexperado: " + e.getMessage()); |
| 339 | 0 | e.printStackTrace(Util.out); |
| 340 | 0 | tabela.setValueAt("erro", i, 0); |
| 341 | |
} finally { |
| 342 | 0 | try { |
| 343 | 0 | ftp.printWorkingDirectory(); |
| 344 | 0 | } catch (IOException e) { |
| 345 | 0 | } |
| 346 | |
try { |
| 347 | 0 | ((OutputStream) streamDestino).close(); |
| 348 | 0 | ((InputStream) streamOrigem).close(); |
| 349 | 0 | } catch (Exception e) { |
| 350 | 0 | } |
| 351 | 0 | } |
| 352 | 0 | posTransfer(i); |
| 353 | |
|
| 354 | |
|
| 355 | 0 | } else if (acao.equals("apagar")) { |
| 356 | |
|
| 357 | |
|
| 358 | 0 | if (arquivo.equals("* todos")) { |
| 359 | |
try { |
| 360 | 0 | for (FTPFile remote : remoteFiles) { |
| 361 | 0 | ftp.deleteFile(remote.getName()); |
| 362 | 0 | Util.log("Removendo arquivo remoto " + remote.getName()); |
| 363 | 0 | transmitido += remote.getSize(); |
| 364 | 0 | Util.out.println("Processado " + transmitido + " de " + totalBytes); |
| 365 | 0 | barra.setValue((int) transmitido); |
| 366 | 0 | lblKbytes.setText(Math.round((float) transmitido / 1024) + " Kb"); |
| 367 | |
} |
| 368 | |
|
| 369 | |
|
| 370 | 0 | ftp.changeWorkingDirectory(ftpRoot); |
| 371 | |
|
| 372 | 0 | ftp.removeDirectory(albumID); |
| 373 | 0 | tabela.setValueAt("ok", i, 0); |
| 374 | |
|
| 375 | 0 | } catch (Exception e) { |
| 376 | 0 | tabela.setValueAt("erro", i, 0); |
| 377 | 0 | log.error(e); |
| 378 | 0 | } |
| 379 | |
|
| 380 | |
} else { |
| 381 | 0 | for (FTPFile remote : remoteFiles) { |
| 382 | 0 | if (remote.getName().equals(arquivo)) { |
| 383 | 0 | remoteFile = remote; |
| 384 | 0 | break; |
| 385 | |
} |
| 386 | |
} |
| 387 | |
|
| 388 | 0 | if (remoteFile == null) { |
| 389 | 0 | tabela.setValueAt("ok - ne", i, 0); |
| 390 | |
} else { |
| 391 | 0 | tabela.setValueAt(Long.toString(remoteFile.getSize()), i, 5); |
| 392 | |
try { |
| 393 | 0 | ftp.deleteFile(arquivo); |
| 394 | 0 | tabela.setValueAt("ok", i, 0); |
| 395 | |
|
| 396 | 0 | posTransfer(i); |
| 397 | 0 | } catch (Exception e) { |
| 398 | 0 | tabela.setValueAt("erro", i, 0); |
| 399 | 0 | } |
| 400 | |
} |
| 401 | |
} |
| 402 | |
|
| 403 | |
|
| 404 | 0 | } else if (acao.equals("receber")) { |
| 405 | |
try { |
| 406 | |
|
| 407 | 0 | if (diretorioDownload == null) { |
| 408 | 0 | diretorioDownload = albunsRoot.getAbsolutePath() + File.separator + albumID; |
| 409 | 0 | File temp = new File(diretorioDownload); |
| 410 | |
|
| 411 | 0 | if (!temp.isDirectory()) { |
| 412 | 0 | temp.mkdir(); |
| 413 | 0 | Util.log("Criando diretório " + diretorioDownload); |
| 414 | |
} |
| 415 | 0 | temp = null; |
| 416 | |
} |
| 417 | 0 | arqDestino = diretorioDownload + File.separator + arquivo; |
| 418 | 0 | Util.out.println(arquivo + " -> " + arqDestino); |
| 419 | |
|
| 420 | 0 | streamOrigem = |
| 421 | |
new BufferedInputStream( |
| 422 | |
ftp.retrieveFileStream(arquivo), |
| 423 | |
ftp.getBufferSize()); |
| 424 | |
|
| 425 | 0 | streamDestino = |
| 426 | |
new FileOutputStream(arqDestino); |
| 427 | |
|
| 428 | 0 | this.transfereArquivo((InputStream) streamOrigem, (OutputStream) streamDestino, Long.parseLong(tabela.getValueAt(i, 5).toString())); |
| 429 | 0 | tabela.setValueAt("ok", i, 0); |
| 430 | |
|
| 431 | |
|
| 432 | 0 | posTransfer(i); |
| 433 | |
|
| 434 | 0 | } catch (IOException ioE) { |
| 435 | 0 | Util.err.println("Erro de transmissão: " + ioE.getMessage() + " " |
| 436 | |
+ ((CopyStreamException) ioE).getIOException().getMessage()); |
| 437 | 0 | tabela.setValueAt("erro", i, 0); |
| 438 | 0 | log.error(ioE); |
| 439 | 0 | } catch (Exception e) { |
| 440 | 0 | Util.err.println("Erro: "); |
| 441 | 0 | log.error(e); |
| 442 | 0 | tabela.setValueAt("erro", i, 0); |
| 443 | |
} finally { |
| 444 | 0 | try { |
| 445 | 0 | ftp.printWorkingDirectory(); |
| 446 | 0 | } catch (IOException e) { |
| 447 | 0 | } |
| 448 | |
try { |
| 449 | 0 | ((InputStream) streamOrigem).close(); |
| 450 | 0 | ((OutputStream) streamDestino).close(); |
| 451 | 0 | } catch (IOException e) { |
| 452 | 0 | } |
| 453 | 0 | } |
| 454 | |
} |
| 455 | |
|
| 456 | 0 | ultimoID = albumID; |
| 457 | |
} |
| 458 | 0 | ftp.disconnect("transmissão terminada"); |
| 459 | 0 | } |
| 460 | |
|
| 461 | |
private void preProcessBatch() { |
| 462 | |
String acao; |
| 463 | |
Arquivo tmpArq; |
| 464 | 0 | int i, j = 0; |
| 465 | |
|
| 466 | |
|
| 467 | 0 | for (i = 0; i < tabela.getRowCount(); i++) { |
| 468 | 0 | acao = tabela.getValueAt(i, 1).toString(); |
| 469 | 0 | if (acao.equals("enviar")) { |
| 470 | 0 | totalBytes += Long.parseLong(tabela.getValueAt(i, 5).toString()); |
| 471 | |
} |
| 472 | 0 | if (acao.equals("receber")) { |
| 473 | 0 | Util.log("Calculando bytes a serem recebidos (álbum " + tabela.getValueAt(i, 2) + ")"); |
| 474 | 0 | tmpArq = (Arquivo) ftp.getListaArquivos().get(i); |
| 475 | |
|
| 476 | 0 | if (tmpArq.getNomeArquivo().equals("* todos")) { |
| 477 | |
|
| 478 | |
try { |
| 479 | 0 | Util.out.println("Convertendo: " + tmpArq.getAlbumID()); |
| 480 | |
|
| 481 | |
|
| 482 | 0 | ftp.getListaArquivos().remove(i--); |
| 483 | 0 | ftp.cd(Integer.toString(tmpArq.getAlbumID())); |
| 484 | 0 | remoteFiles = ftp.listFiles(); |
| 485 | 0 | for (FTPFile remote : remoteFiles) { |
| 486 | 0 | ftp.getListaArquivos().add( |
| 487 | |
new Arquivo(tmpArq.getLinhaComando(), 2, |
| 488 | |
tmpArq.getAlbumID(), tmpArq.getFotoID(), remote.getName(), |
| 489 | |
remote.getSize())); |
| 490 | 0 | totalBytes += remote.getSize(); |
| 491 | |
} |
| 492 | 0 | } catch (SyncException se) { |
| 493 | 0 | Util.log(se.getMessage()); |
| 494 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 495 | 0 | } catch (Exception e) { |
| 496 | 0 | log.error(e); |
| 497 | 0 | } |
| 498 | |
} else { |
| 499 | |
|
| 500 | |
try { |
| 501 | 0 | ftp.cd(Integer.toString(tmpArq.getAlbumID())); |
| 502 | 0 | remoteFiles = this.ftp.listFiles(); |
| 503 | 0 | for (FTPFile remote : remoteFiles) { |
| 504 | 0 | if (tmpArq.getNomeArquivo().equals(remote.getName())) { |
| 505 | 0 | totalBytes += remote.getSize(); |
| 506 | 0 | tmpArq.setTamanho(remote.getSize()); |
| 507 | 0 | break; |
| 508 | |
} |
| 509 | |
} |
| 510 | 0 | } catch (SyncException se) { |
| 511 | 0 | Util.log(se.getMessage()); |
| 512 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 513 | 0 | } catch (Exception e) { |
| 514 | 0 | log.error(e); |
| 515 | 0 | } |
| 516 | |
} |
| 517 | |
} |
| 518 | 0 | if (acao.equals("apagar")) { |
| 519 | 0 | Util.log("Calculando bytes a serem apagados (álbum " + tabela.getValueAt(i, 2) + ")"); |
| 520 | 0 | tmpArq = (Arquivo) ftp.getListaArquivos().get(i); |
| 521 | 0 | if (tmpArq.getNomeArquivo().equals("* todos")) { |
| 522 | |
|
| 523 | |
try { |
| 524 | 0 | Util.out.println("Convertendo: " + tmpArq.getAlbumID()); |
| 525 | 0 | ftp.cd(Integer.toString(tmpArq.getAlbumID())); |
| 526 | 0 | remoteFiles = this.ftp.listFiles(); |
| 527 | 0 | for (FTPFile remote : remoteFiles) { |
| 528 | 0 | totalBytes += remote.getSize(); |
| 529 | |
} |
| 530 | 0 | } catch (SyncException se) { |
| 531 | 0 | Util.log(se.getMessage()); |
| 532 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 533 | 0 | } catch (Exception e) { |
| 534 | 0 | log.error(e); |
| 535 | 0 | } |
| 536 | |
} else { |
| 537 | |
|
| 538 | |
try { |
| 539 | 0 | ftp.cd(Integer.toString(tmpArq.getAlbumID())); |
| 540 | 0 | remoteFiles = this.ftp.listFiles(); |
| 541 | 0 | for (FTPFile remote : remoteFiles) { |
| 542 | 0 | if (tmpArq.getNomeArquivo().equals(remote.getName())) { |
| 543 | 0 | totalBytes += remote.getSize(); |
| 544 | 0 | tmpArq.setTamanho(remote.getSize()); |
| 545 | 0 | break; |
| 546 | |
} |
| 547 | |
} |
| 548 | 0 | } catch (SyncException se) { |
| 549 | 0 | Util.log(se.getMessage()); |
| 550 | 0 | ftp.disconnect("não foi possivel entrar no diretorio"); |
| 551 | 0 | } catch (Exception e) { |
| 552 | 0 | log.error(e); |
| 553 | 0 | } |
| 554 | |
} |
| 555 | |
} |
| 556 | |
} |
| 557 | 0 | } |
| 558 | |
|
| 559 | |
private void posTransfer(final int i) throws NumberFormatException { |
| 560 | 0 | transmitido += Long.parseLong(tabela.getValueAt(i, 5).toString()); |
| 561 | 0 | Util.out.println("Processado " + transmitido + " de " + totalBytes); |
| 562 | 0 | barra.setValue((int) transmitido); |
| 563 | 0 | lblKbytes.setText(Math.round((float) transmitido / 1024) + " Kb"); |
| 564 | 0 | } |
| 565 | |
|
| 566 | |
private void transfereArquivo(InputStream streamOrigem, OutputStream streamDestino, long streamSize) |
| 567 | |
throws CopyStreamException, |
| 568 | |
IOException { |
| 569 | |
|
| 570 | 0 | barraArquivoAtual.setValue(0); |
| 571 | 0 | barraArquivoAtual.setMaximum((int) streamSize); |
| 572 | 0 | lblKbytesArquivoAtual.setText("0 Kb"); |
| 573 | |
|
| 574 | |
try { |
| 575 | 0 | ftp.transferFile(streamOrigem, streamDestino, streamSize); |
| 576 | 0 | } catch (IOException e) { |
| 577 | |
try { |
| 578 | 0 | streamOrigem.close(); |
| 579 | 0 | streamDestino.close(); |
| 580 | 0 | } catch (IOException f) { |
| 581 | 0 | } |
| 582 | 0 | throw e; |
| 583 | 0 | } |
| 584 | |
|
| 585 | 0 | } |
| 586 | |
} |