List of usage examples for org.apache.commons.net.ftp FTPReply isPositiveCompletion
public static boolean isPositiveCompletion(int reply)
From source file:ch.cyberduck.core.ftp.FTPStatListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {// w ww . ja v a 2 s .c o m final int response = session.getClient().stat(directory.getAbsolute()); if (FTPReply.isPositiveCompletion(response)) { return reader.read(directory, this.parse(response, session.getClient().getReplyStrings()), listener); } else { throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch (IOException e) { throw new FTPExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
From source file:joshuatee.wx.UtilityFTP.java
public static String[] GetNidsArr(Context c, String url, String path, String frame_cnt_str) { int frame_cnt = Integer.parseInt(frame_cnt_str); String[] nids_arr = new String[frame_cnt]; try {//from w ww .j a v a 2 s. co m FTPClient ftp = new FTPClient(); //String user = "ftp"; //String pass = "anonymous"; ftp.connect(url); if (!ftp.login("ftp", "anonymous")) { ftp.logout(); } ftp.setFileType(FTP.BINARY_FILE_TYPE); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); } ftp.enterLocalPassiveMode(); ftp.changeWorkingDirectory(path); //reply = ftp.getReplyCode(); FTPFile[] ftpFiles = ftp.listFiles(); //get newest .xml file name from ftp server java.util.Date lastMod = ftpFiles[0].getTimestamp().getTime(); FTPFile choice = ftpFiles[0]; for (FTPFile file : ftpFiles) { if (file.getTimestamp().getTime().after(lastMod) && !file.getName().equals("sn.last")) { choice = file; lastMod = file.getTimestamp().getTime(); } } int seq = Integer.parseInt(choice.getName().replace("sn.", "")); // was ALl int j = 0; int k = seq - frame_cnt + 1; for (j = 0; j < frame_cnt; j++) { // files range from 0000 to 0250, if num is negative add 251 int tmp_k = k; if (tmp_k < 0) tmp_k = tmp_k + 251; nids_arr[j] = "sn." + String.format("%4s", Integer.toString(tmp_k)).replace(' ', '0'); k++; } FileOutputStream fos; for (j = 0; j < frame_cnt; j++) { fos = c.openFileOutput(nids_arr[j], Context.MODE_PRIVATE); ftp.retrieveFile(nids_arr[j], fos); fos.close(); } ftp.logout(); ftp.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } return nids_arr; }
From source file:m09_uf3_7.ClientFTP.java
private void conectar() throws IOException { //realitzar conexi amb connect(), ip i port // --CODE--/*from w w w .j a v a2s . com*/ ftp.connect(server, port); //realitzar login amb user i password. //--CODE-- login = ftp.login(user, pass); //Comprobaci de connexi amb valor de retorn de login if (login) { System.out.println("Connexi realitzada correctament!"); } else { System.out.println("No s'ha pogut conectar... revisa la configuraci!"); } //Comprobaci de valor de connexi amb els metode getReplyCode() i isPositiveCompletion(reply) //--CODE-- int x = ftp.getReplyCode(); if (FTPReply.isPositiveCompletion(x)) { System.out.println("se a conectao"); } else { System.out.println("no se a conectao"); } }
From source file:com.igormaznitsa.zxpoly.utils.ROMLoader.java
static byte[] loadFTPArchive(final String host, final String path, final String name, final String password) throws IOException { final FTPClient client = new FTPClient(); client.connect(host);/*from w w w .j av a 2 s .c o m*/ int replyCode = client.getReplyCode(); if (FTPReply.isPositiveCompletion(replyCode)) { try { client.login(name == null ? "" : name, password == null ? "" : password); client.setFileType(FTP.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); final ByteArrayOutputStream out = new ByteArrayOutputStream(300000); if (client.retrieveFile(path, out)) { return out.toByteArray(); } else { throw new IOException( "Can't load file 'ftp://" + host + path + "\' status=" + client.getReplyCode()); } } finally { client.disconnect(); } } else { client.disconnect(); throw new IOException("Can't connect to ftp '" + host + "'"); } }
From source file:eu.ggnet.dwoss.misc.op.listings.FtpTransfer.java
/** * Uploads a some files to a remove ftp host. * <p/>//from ww w .j ava2 s .c o m * @param config the config for he connection. * @param uploads the upload commands * @param monitor an optional monitor. * @throws java.net.SocketException * @throws java.io.IOException */ public static void upload(ConnectionConfig config, IMonitor monitor, UploadCommand... uploads) throws SocketException, IOException { if (uploads == null || uploads.length == 0) return; SubMonitor m = SubMonitor.convert(monitor, "FTP Transfer", toWorkSize(uploads) + 4); m.message("verbinde"); m.start(); FTPClient ftp = new FTPClient(); ftp.addProtocolCommandListener(PROTOCOL_TO_LOGGER); try { ftp.connect(config.getHost(), config.getPort()); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) throw new IOException("FTPReply.isPositiveCompletion(ftp.getReplyCode()) = false"); if (!ftp.login(config.getUser(), config.getPass())) throw new IOException("Login with " + config.getUser() + " not successful"); L.info("Connected to {} idenfied by {}", config.getHost(), ftp.getSystemType()); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); for (UploadCommand upload : uploads) { m.worked(1, "uploading to " + upload.getPath()); ftp.changeWorkingDirectory(upload.getPath()); deleteFilesByType(ftp, upload.getDeleteFileTypes()); for (File file : upload.getFiles()) { m.worked(1, "uploading to " + upload.getPath() + " file " + file.getName()); try (InputStream input = new FileInputStream(file)) { if (!ftp.storeFile(file.getName(), input)) throw new IOException("Cannot store file " + file + " on server!"); } } } m.finish(); } finally { // just cleaning up try { ftp.logout(); } catch (IOException e) { } if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { } } } }
From source file:com.webarch.common.net.ftp.FtpService.java
/** * /*from w ww .j av a 2s .co m*/ * * @param fileName ?? * @param path ftp? * @param fileStream ? * @return true/false ? */ public boolean uploadFile(String fileName, String path, InputStream fileStream) { boolean success = false; FTPClient ftpClient = new FTPClient(); try { int replyCode; ftpClient.connect(url, port); ftpClient.login(userName, password); replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { return false; } ftpClient.changeWorkingDirectory(path); ftpClient.storeFile(fileName, fileStream); fileStream.close(); ftpClient.logout(); success = true; } catch (IOException e) { logger.error("ftp?", e); } finally { if (ftpClient.isConnected()) { try { ftpClient.disconnect(); } catch (IOException e) { logger.error("ftp?", e); } } } return success; }
From source file:it.unisannio.srss.dame.android.services.FTPService.java
public void connect() throws SocketException, IOException { int reply;/*from w ww. j a v a 2 s .c om*/ ftp.connect(url, port); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); Log.e(TAG, "Exception in connecting to FTP Server: code " + reply); } ftp.login(user, pwd); ftp.setFileType(FTP.BINARY_FILE_TYPE); if (passive) ftp.enterLocalPassiveMode(); else ftp.enterLocalActiveMode(); }
From source file:at.beris.virtualfile.client.ftp.FtpClient.java
@Override public void connect() throws IOException { LOGGER.info("Connecting to " + username() + "@" + host() + ":" + String.valueOf(port())); reconnect = true;/*from w w w . jav a 2s . c om*/ ftpClient.connect(host(), port()); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { disconnect(); return; } login(); setFileType(FTP.BINARY_FILE_TYPE); }
From source file:car.PasserelleRestTest.java
public PasserelleRestTest() throws IOException { this.currentDirectory = new String(); ftp.configure(config);//from w ww.j av a2 s .c o m ftp.connect("127.0.0.1", 4000); /* we make sure we are inputStream passive mode */ //ftp.enterLocalPassiveMode(); /* we check the connection is OK */ int replyCode = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { System.out.println("[passerelle] : Connection failed"); return; } else { System.out.println("[passerelle] : Connection success"); } boolean login = ftp.login("nico", "password"); if (!login) { ftp.disconnect(); System.out.println("Could not login to the server"); return; } else { System.out.print("[passerelle]: " + ftp.getReplyString()); } /* we set the current directory */ this.currentDirectory = ftp.printWorkingDirectory(); System.out.println("current directory = " + this.currentDirectory); this.files = ftp.listFiles(this.currentDirectory); }
From source file:FileHandler.JakartaFtpWrapper.java
/** A convenience method for connecting and logging in */ public boolean connectAndLogin(String host, String userName, String password) throws IOException, UnknownHostException, FTPConnectionClosedException { boolean success = false; connect(host);//from www .j ava2 s .c om int reply = getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) success = login(userName, password); else throw new IOException(String.format("Host %s failed to reply.....", host)); if (!success) disconnect(); return success; }