Subversion Repository Public Repository

litesoft

Diff Revisions 313 vs 315 for /trunk/Java/ScarPlus/src/com/esotericsoftware/scar/FTP.java

Diff revisions: vs.
  @@ -6,66 +6,67 @@
6 6 import org.apache.commons.net.ftp.*;
7 7
8 8 import com.esotericsoftware.filesystem.*;
9 + import com.esotericsoftware.utils.*;
9 10
10 11 import static com.esotericsoftware.minlog.Log.*;
11 12
12 13 public class FTP
13 14 {
14 15 static public boolean upload( String server, String user, String password, String dir, Paths paths, boolean passive )
15 - throws IOException
16 16 {
17 - FTPClient ftp = new FTPClient();
18 - InetAddress address = InetAddress.getByName( server );
19 - if ( DEBUG )
17 + try
20 18 {
21 - debug( "Connecting to FTP server: " + address );
22 - }
23 - ftp.connect( address );
24 - if ( passive )
25 - {
26 - ftp.enterLocalPassiveMode();
27 - }
28 - if ( !ftp.login( user, password ) )
29 - {
30 - if ( ERROR )
19 + FTPClient ftp = new FTPClient();
20 + InetAddress address = InetAddress.getByName( server );
21 + if ( DEBUG )
31 22 {
32 - error( "FTP login failed for user: " + user );
23 + debug( "Connecting to FTP server: " + address );
33 24 }
34 - return false;
35 - }
36 - if ( !ftp.changeWorkingDirectory( dir ) )
37 - {
38 - if ( ERROR )
25 + ftp.connect( address );
26 + if ( passive )
39 27 {
40 - error( "FTP directory change failed: " + dir );
28 + ftp.enterLocalPassiveMode();
41 29 }
42 - return false;
43 - }
44 - ftp.setFileType( org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE );
45 - for ( String path : paths.getFullPaths() )
46 - {
47 - if ( INFO )
30 + if ( !ftp.login( user, password ) )
48 31 {
49 - info( "FTP upload: " + path );
32 + if ( ERROR )
33 + {
34 + error( "FTP login failed for user: " + user );
35 + }
36 + return false;
50 37 }
51 - BufferedInputStream input = new BufferedInputStream( new FileInputStream( path ) );
52 - try
38 + if ( !ftp.changeWorkingDirectory( dir ) )
53 39 {
54 - ftp.storeFile( new File( path ).getName(), input );
40 + if ( ERROR )
41 + {
42 + error( "FTP directory change failed: " + dir );
43 + }
44 + return false;
55 45 }
56 - finally
46 + ftp.setFileType( org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE );
47 + for ( String path : paths.getFullPaths() )
57 48 {
49 + if ( INFO )
50 + {
51 + info( "FTP upload: " + path );
52 + }
53 + BufferedInputStream input = new BufferedInputStream( new FileInputStream( path ) );
58 54 try
59 55 {
60 - input.close();
56 + ftp.storeFile( new File( path ).getName(), input );
61 57 }
62 - catch ( Exception ignored )
58 + finally
63 59 {
60 + FileUtil.dispose( input );
64 61 }
65 62 }
63 + ftp.logout();
64 + ftp.disconnect();
65 + }
66 + catch ( IOException e )
67 + {
68 + throw new WrappedIOException( e );
66 69 }
67 - ftp.logout();
68 - ftp.disconnect();
69 70 return true;
70 71 }
71 72 }