org.apache.commons.net.PrintCommandListener Java Examples
The following examples show how to use
org.apache.commons.net.PrintCommandListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ftp.java From Lottery with GNU General Public License v2.0 | 6 votes |
private FTPClient getClient() throws SocketException, IOException { FTPClient ftp = new FTPClient(); ftp.addProtocolCommandListener(new PrintCommandListener( new PrintWriter(System.out))); ftp.setDefaultPort(getPort()); ftp.connect(getIp()); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { log.warn("FTP server refused connection: {}", getIp()); ftp.disconnect(); return null; } if (!ftp.login(getUsername(), getPassword())) { log.warn("FTP server refused login: {}, user: {}", getIp(), getUsername()); ftp.logout(); ftp.disconnect(); return null; } ftp.setControlEncoding(getEncoding()); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); return ftp; }
Example #2
Source File: FTPClientTemplate.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 返回一个FTPClient实例 * * @throws Exception */ private FTPClient getFTPClient()throws Exception { if (ftpClientThreadLocal.get() != null && ftpClientThreadLocal.get().isConnected()) { return ftpClientThreadLocal.get(); } else { FTPClient ftpClient = new FTPClient(); //构造一个FtpClient实例 ftpClient.setControlEncoding(encoding); //设置字符集 connect(ftpClient); //连接到ftp服务器 //设置为passive模式 if (passiveMode) { ftpClient.enterLocalPassiveMode(); String replystr=ftpClient.getReplyString(); ftpClient.sendCommand("PASV"); replystr=ftpClient.getReplyString(); } setFileType(ftpClient); //设置文件传输类型 try { ftpClient.setSoTimeout(clientTimeout); ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); } catch (SocketException e) { throw new Exception("Set timeout error.", e); } ftpClientThreadLocal.set(ftpClient); return ftpClient; } }
Example #3
Source File: FTPServerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private FTPClient connectClient() throws IOException { FTPClient ftp = new FTPClient(); if(logger.isDebugEnabled()) { ftp.addProtocolCommandListener(new PrintCommandListener( new PrintWriter(System.out))); } ftp.connect(HOSTNAME, ftpConfigSection.getFTPPort()); return ftp; }
Example #4
Source File: FtpClient.java From spring-boot with Apache License 2.0 | 5 votes |
private void connectClientAndCheckStatus() throws SocketException, IOException, FtpException { log.info("Connected to " + host + ":" + port + " via FTP ..."); ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); // 打印执行的命令? ftpClient.connect(host, port); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) throw new FtpException(String.format(STATUS_ERROR_MESSAGE, host, port)); }
Example #5
Source File: FTPUploader.java From journaldev with MIT License | 5 votes |
public FTPUploader(String host, String user, String pwd) throws Exception{ ftp = new FTPClient(); ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); int reply; ftp.connect(host); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); throw new Exception("Exception in connecting to FTP Server"); } ftp.login(user, pwd); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); }
Example #6
Source File: FTPDownloader.java From journaldev with MIT License | 5 votes |
public FTPDownloader(String host, String user, String pwd) throws Exception { ftp = new FTPClient(); ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); int reply; ftp.connect(host); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); throw new Exception("Exception in connecting to FTP Server"); } ftp.login(user, pwd); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); }
Example #7
Source File: FtpClient.java From tutorials with MIT License | 5 votes |
void open() throws IOException { ftp = new FTPClient(); ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); ftp.connect(server, port); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); throw new IOException("Exception in connecting to FTP Server"); } ftp.login(user, password); }
Example #8
Source File: FtpClient.java From konduit-serving with Apache License 2.0 | 4 votes |
@Override public void connect(String host) throws IOException { ftp.connect("localhost", port); ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); }