本文整理匯總了Java中org.apache.commons.net.ftp.FTPReply.isPositiveCompletion方法的典型用法代碼示例。如果您正苦於以下問題:Java FTPReply.isPositiveCompletion方法的具體用法?Java FTPReply.isPositiveCompletion怎麽用?Java FTPReply.isPositiveCompletion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.net.ftp.FTPReply
的用法示例。
在下文中一共展示了FTPReply.isPositiveCompletion方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ftpLogin
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
/**
* @return 判斷是否登入成功
* */
public boolean ftpLogin() {
boolean isLogin = false;
FTPClientConfig ftpClientConfig = new FTPClientConfig();
ftpClientConfig.setServerTimeZoneId(TimeZone.getDefault().getID());
this.ftpClient.setControlEncoding("GBK");
this.ftpClient.configure(ftpClientConfig);
try {
if (this.intPort > 0) {
this.ftpClient.connect(this.strIp, this.intPort);
} else {
this.ftpClient.connect(this.strIp);
}
// FTP服務器連接回答
int reply = this.ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
this.ftpClient.disconnect();
System.out.println("登錄FTP服務失敗!");
return isLogin;
}
this.ftpClient.login(this.user, this.password);
// 設置傳輸協議
this.ftpClient.enterLocalPassiveMode();
this.ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
System.out.println("恭喜" + this.user + "成功登陸FTP服務器");
//logger.info("恭喜" + this.user + "成功登陸FTP服務器");
isLogin = true;
} catch (Exception e) {
e.printStackTrace();
System.out.println(this.user + "登錄FTP服務失敗!" + e.getMessage());
//logger.error(this.user + "登錄FTP服務失敗!" + e.getMessage());
}
this.ftpClient.setBufferSize(1024 * 2);
this.ftpClient.setDataTimeout(30 * 1000);
return isLogin;
}
示例2: download
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public static byte[] download(String url, int port, String username, String password, String remotePath,
String fileName) throws IOException {
FTPClient ftp = new FTPClient();
ftp.setConnectTimeout(5000);
ftp.setAutodetectUTF8(true);
ftp.setCharset(CharsetUtil.UTF_8);
ftp.setControlEncoding(CharsetUtil.UTF_8.name());
try {
ftp.connect(url, port);
ftp.login(username, password);// 登錄
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
ftp.disconnect();
throw new IOException("login fail!");
}
ftp.changeWorkingDirectory(remotePath);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
FTPFile[] fs = ftp.listFiles();
for (FTPFile ff : fs) {
if (ff.getName().equals(fileName)) {
try (ByteArrayOutputStream is = new ByteArrayOutputStream();) {
ftp.retrieveFile(ff.getName(), is);
byte[] result = is.toByteArray();
return result;
}
}
}
ftp.logout();
} finally {
if (ftp.isConnected()) {
ftp.disconnect();
}
}
return null;
}
示例3: connect
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public boolean connect(String hostname, int port, String username,
String password) throws IOException {
// ���ӵ�FTP������
ftpClient.connect(hostname, port);
// �������Ĭ�϶˿ڣ�����ʹ��ftp.connect(url)�ķ�ʽֱ������FTP������
if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
if (ftpClient.login(username, password)) {
return true;
}
}
disconnect();
return false;
}
示例4: connectClient
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
@Override
public boolean connectClient() throws IOException {
boolean isLoggedIn = true;
client.setAutodetectUTF8(true);
client.setControlEncoding("UTF-8");
client.connect(host, port);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.enterLocalPassiveMode();
client.login(username, password);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply);
//throw new IOException("failed to connect to FTP server");
isLoggedIn = false;
}
return isLoggedIn;
}
示例5: initFtpClient
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
private FTPClient initFtpClient(String remoteDir) throws IOException {
FTPClient ftp = new FTPClient();
// 設置連接超時時間
ftp.setConnectTimeout(CONNECT_TIMEOUT);
// 設置傳輸文件名編碼方式
ftp.setControlEncoding(CONTROL_ENCODING);
ftp.connect(host, ftpPort);
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
logger.debug("無法連接FTP");
return null;
}
boolean loginRet = ftp.login(ftpUsername, ftpPassword);
if (!loginRet) {
logger.debug("FTP登錄失敗");
return null;
}
// 進入被動模式
ftp.enterLocalPassiveMode();
boolean changeDirResult = MKDAndCWD(ftp, remoteDir);
if (!changeDirResult) {
logger.debug("創建/切換文件夾失敗");
return null;
}
// 傳輸二進製文件
ftp.setFileType(FTP.BINARY_FILE_TYPE);
return ftp;
}
示例6: find
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
@Override
public PathAttributes find(final Path file) throws BackgroundException {
if(file.isRoot()) {
return PathAttributes.EMPTY;
}
try {
if(session.getClient().hasFeature(FTPCmd.MLST.getCommand())) {
if(!FTPReply.isPositiveCompletion(session.getClient().sendCommand(FTPCmd.MLST, file.getAbsolute()))) {
throw new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString());
}
final FTPDataResponseReader reader = new FTPMlsdListResponseReader();
final AttributedList<Path> attributes
= reader.read(file.getParent(), Arrays.asList(session.getClient().getReplyStrings()), new DisabledListProgressListener());
if(attributes.contains(file)) {
return attributes.get(attributes.indexOf(file)).attributes();
}
}
throw new InteroperabilityException("No support for MLST in reply to FEAT");
}
catch(IOException e) {
throw new FTPExceptionMappingService().map("Failure to read attributes of {0}", e, file);
}
}
示例7: connect
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
/**
* Connect to the FTP server using configuration parameters *
*
* @return An FTPClient instance
* @throws IOException
*/
private FTPClient connect() throws IOException {
FTPClient client = null;
Configuration conf = getConf();
String host = conf.get(FS_FTP_HOST);
int port = conf.getInt(FS_FTP_HOST_PORT, FTP.DEFAULT_PORT);
String user = conf.get(FS_FTP_USER_PREFIX + host);
String password = conf.get(FS_FTP_PASSWORD_PREFIX + host);
client = new FTPClient();
client.connect(host, port);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw NetUtils.wrapException(host, port,
NetUtils.UNKNOWN_HOST, 0,
new ConnectException("Server response " + reply));
} else if (client.login(user, password)) {
client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.setBufferSize(DEFAULT_BUFFER_SIZE);
} else {
throw new IOException("Login failed on server - " + host + ", port - "
+ port + " as user '" + user + "'");
}
return client;
}
示例8: getSystemType
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public String getSystemType() throws IOException {
if(this.__systemName == null) {
if(FTPReply.isPositiveCompletion(this.syst())) {
this.__systemName = ((String)this._replyLines.get(this._replyLines.size() - 1)).substring(4);
} else {
String systDefault = System.getProperty("org.apache.commons.net.ftp.systemType.default");
if(systDefault == null) {
throw new IOException("Unable to determine system type - response: " + this.getReplyString());
}
this.__systemName = systDefault;
}
}
return this.__systemName;
}
示例9: connect
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
/**
* 連接FTP服務器
* @param host FTP服務器地址
* @param port FTP服務器端口號
* @param username 用戶名
* @param password 密碼
* @return
*/
public static boolean connect(String host, int port, String username, String password) {
try{
ftpClient = new FTPClient();
ftpClient.connect(host, port);
// 登錄
ftpClient.login(username, password);
ftpClient.setBufferSize(FTP_SERVER_BUFFER_SIZE_VALUE);
ftpClient.setControlEncoding(FTP_CLIENT_ENCODING);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setDataTimeout(FTP_SERVER_DATA_TIME_OUT);
ftpClient.setSoTimeout(FTP_SERVER_SO_TIME_OUT);
// 檢驗是否連接成功
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
LOGGER.error("連接FTP服務器失敗,響應碼:"+reply);
disConnectionServer();
return false;
}
}catch(IOException e){
LOGGER.error("連接FTP服務器失敗",e);
return false;
}
return true;
}
示例10: exists
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public boolean exists(String filename) throws FileSystemException {
// we have to be connected
if (ftp == null) {
throw new FileSystemException("Not yet connected to FTP server");
}
try {
// check if the file already exists
FTPFile[] files = ftp.listFiles(filename);
// did this command succeed?
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
throw new FileSystemException("FTP server failed to get file listing (reply=" + ftp.getReplyString() + ")");
}
if (files != null && files.length > 0) {
// this file already exists
return true;
} else {
return false;
}
} catch (IOException e) {
throw new FileSystemException("Underlying IO exception with FTP server while checking if file exists", e);
}
}
示例11: getCurrentDirectory
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public String getCurrentDirectory() {
if ( !ftpclient.isConnected() ){
errorText = "not connected";
succeeded = false;
return null;
}
String curdir = null;
try{
curdir = ftpclient.printWorkingDirectory();
errorCode = ftpclient.getReplyCode();
succeeded = FTPReply.isPositiveCompletion(errorCode);
}catch(Exception e){
errorCode = ftpclient.getReplyCode();
errorText = e.getMessage();
}finally{
setStatusData();
}
return curdir;
}
示例12: connectClientAndCheckStatus
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
private void connectClientAndCheckStatus() throws SocketException, IOException, FTPException {
LOGGER.debug("Connecting to {}:{}", host, port);
ftpClient.connect(host, port);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
LOGGER.debug("Connection not made.");
LOGGER.debug("Response status: {}", replyCode);
LOGGER.debug("Disconnecting");
ftpClient.disconnect();
LOGGER.debug("Disconnected");
throw new ClientConnectionException(String.format("The host %s on port %d returned a bad status code.", host, port));
}
}
示例13: makeDirectory
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public boolean makeDirectory(String file) {
if ( !ftpclient.isConnected() ){
errorText = "not connected";
succeeded = false;
return false;
}
boolean bResult = false;
try{
bResult = ftpclient.makeDirectory(file);
errorCode = ftpclient.getReplyCode();
succeeded = FTPReply.isPositiveCompletion(errorCode);
}catch(Exception e){
errorCode = ftpclient.getReplyCode();
errorText = e.getMessage();
}finally{
setStatusData();
}
return bResult;
}
示例14: removeFile
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
public boolean removeFile(String file) {
if ( !ftpclient.isConnected() ){
errorText = "not connected";
succeeded = false;
return false;
}
boolean bResult = false;
try{
bResult = ftpclient.deleteFile(file);
errorCode = ftpclient.getReplyCode();
succeeded = FTPReply.isPositiveCompletion(errorCode);
}catch(Exception e){
errorCode = ftpclient.getReplyCode();
errorText = e.getMessage();
}finally{
setStatusData();
}
return bResult;
}
示例15: connect
import org.apache.commons.net.ftp.FTPReply; //導入方法依賴的package包/類
/**
* Connect to the FTP server using configuration parameters *
*
* @return An FTPClient instance
* @throws IOException
*/
private FTPClient connect() throws IOException {
FTPClient client = null;
Configuration conf = getConf();
String host = conf.get("fs.ftp.host");
int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
String user = conf.get("fs.ftp.user." + host);
String password = conf.get("fs.ftp.password." + host);
client = new FTPClient();
client.connect(host, port);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new IOException("Server - " + host
+ " refused connection on port - " + port);
} else if (client.login(user, password)) {
client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.setBufferSize(DEFAULT_BUFFER_SIZE);
} else {
throw new IOException("Login failed on server - " + host + ", port - "
+ port);
}
return client;
}