List of usage examples for org.apache.commons.vfs2.provider.ftp FtpClientFactory createConnection
public static FTPClient createConnection(final String hostname, final int port, final char[] username, final char[] password, final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException
From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java
public static void testFtp() { // System.setProperty("http.proxyHost", "proxy.cls.fr"); // adresse IP // System.setProperty("http.proxyPort", "8080"); // System.setProperty("socksProxyHost", "proxy.cls.fr"); // System.setProperty("socksProxyPort", "1080"); try {/* ww w. j a v a 2s . c om*/ // String user = "anonymous"; // String pass = "email"; // String server = "ftp.cls.fr"; // // FTPClient client = new FTPClient(); // client.connect(server); // System.out.print(client.getReplyString()); // int reply = client.getReplyCode(); // if (!FTPReply.isPositiveCompletion(reply)) // { // throw new IllegalArgumentException("cant connect: " + reply); // } // if (!client.login(user, pass)) // { // throw new IllegalArgumentException("login failed"); // } // client.enterLocalPassiveMode(); // client.disconnect(); FileSystemOptions opts = new FileSystemOptions(); // FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); String server = "proxy.cls.fr"; String user = "anonymous@ftp.unidata.ucar.edu"; String pass = ""; server = "ftp.cls.fr"; user = "anonymous"; pass = "email"; server = "proxy-bureautique.cls.fr"; user = "misgw@ftp.cmcc.it"; pass = "myo2010"; StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pass); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); FileObject fo = VFS.getManager().resolveFile( "ftp://proxy-bureautique.cls.fr/GLOBAL_REANALYSIS_PHYS_001_004_a/global-reanalysis-phys-001-004-a-ran-it-cglors-icemod//global-reanalysis-phys-001-004-a-ran-it-cglors-icemod_20090101_20091231_20110331.nc", opts); FTPClient ftpClient = FtpClientFactory.createConnection(server, 21, user.toCharArray(), pass.toCharArray(), ".", opts); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); // } catch (SocketException e) { // // TODO Auto-generated catch block // e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }