本文整理汇总了Java中org.apache.commons.net.ftp.FTPSClient.getReplyCode方法的典型用法代码示例。如果您正苦于以下问题:Java FTPSClient.getReplyCode方法的具体用法?Java FTPSClient.getReplyCode怎么用?Java FTPSClient.getReplyCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.net.ftp.FTPSClient
的用法示例。
在下文中一共展示了FTPSClient.getReplyCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToFTP
import org.apache.commons.net.ftp.FTPSClient; //导入方法依赖的package包/类
public static void connectToFTP(FTPSClient ftp, String ftpServer, int ftpPort) throws SocketException, IOException {
ftp.connect(ftpServer, ftpPort);
// After connection attempt, you should check the reply code to verify
// success.
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
throw new IOException("FTP server refused connection, reply code: " + reply);
}
logger.debug("Connected to " + ftpServer + "."+ftp.getReplyString());
}
示例2: getNewFTPSClient
import org.apache.commons.net.ftp.FTPSClient; //导入方法依赖的package包/类
public FTPClient getNewFTPSClient(Uri path, int mode) throws SocketException, IOException, AuthenticationException{
// Use default port if not set
int port = path.getPort();
if (port<0) {
port = 21; // default port
}
String username="anonymous"; // default user
String password = ""; // default password
NetworkCredentialsDatabase database = NetworkCredentialsDatabase.getInstance();
Credential cred = database.getCredential(path.toString());
if(cred!=null){
password= cred.getPassword();
username = cred.getUsername();
}
FTPSClient ftp= new FTPSClient("TLS", false);
//try to connect
ftp.connect(path.getHost(), port);
//login to server
if(!ftp.login(username, password))
{
ftp.logout();
throw new AuthenticationException();
}
if(mode>=0){
ftp.setFileType(mode);
}
int reply = ftp.getReplyCode();
//FTPReply stores a set of constants for FTP reply codes.
if (!FTPReply.isPositiveCompletion(reply))
{
try {
ftp.disconnect();
} catch (IOException e) {
throw e;
}
return null;
}
//enter passive mode
ftp.enterLocalPassiveMode();
// Set protection buffer size
ftp.execPBSZ(0);
// Set data channel protection to private
ftp.execPROT("P");
return ftp;
}
示例3: connect
import org.apache.commons.net.ftp.FTPSClient; //导入方法依赖的package包/类
/**
* Connect to a FTP server
*/
public void connect()
throws IOException, SecurityException
{
if(this.isSecured())
{
ftpClient = new FTPSClient(false);
((FTPSClient)ftpClient).setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
}
else
ftpClient = new FTPClient();
// suppress login details
ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(
new OutputStreamWriter(System.out,IO.CHARSET)), true));
int keepAliveTimeout = this.getKeepAliveTimeout();
if (keepAliveTimeout > 0) {
ftpClient.setControlKeepAliveTimeout(keepAliveTimeout);
}
int controlKeepAliveReplyTimeout = this.getControlKeepAliveReplyTimeout();
if (controlKeepAliveReplyTimeout > 0)
ftpClient.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeout);
int port = this.getPort();
if(port > 0)
ftpClient.connect(getHost(), getPort());
else
ftpClient.connect(getHost());
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
disconnect();
return;
}
if (!ftpClient.login(this.getUsername(), new String(getPassword())))
throw new SecurityException("login failed");
if (isBinaryTransfer())
{
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
}
else
{
ftpClient.setFileType(FTP.NON_PRINT_TEXT_FORMAT);
ftpClient.setAutodetectUTF8(true);
}
if (isLocalActive())
ftpClient.enterLocalActiveMode();
else
ftpClient.enterLocalPassiveMode();
ftpClient.setUseEPSVwithIPv4(isUseEpsvWithIPv4());
ftpClient.setCharset(this.getCharset());
this.connected = true;
}