本文整理汇总了Java中org.apache.commons.net.ftp.FTPSClient类的典型用法代码示例。如果您正苦于以下问题:Java FTPSClient类的具体用法?Java FTPSClient怎么用?Java FTPSClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FTPSClient类属于org.apache.commons.net.ftp包,在下文中一共展示了FTPSClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FTPSNetworkClient
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
public FTPSNetworkClient(final String host, final int port){
client = new FTPSClient();
this.host = host;
this.port = port;
this.username = "anonymous";
this.password = "";
}
示例2: 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());
}
示例3: createFTPClient
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
@Override
protected FTPSClient createFTPClient() throws Exception {
FTPSClient ftpsClient = new FTPSClient(useImplicit());
FileInputStream fin = new FileInputStream(FTPCLIENT_KEYSTORE);
KeyStore store = KeyStore.getInstance("jks");
store.load(fin, KEYSTORE_PASSWORD.toCharArray());
fin.close();
// initialize key manager factory
KeyManagerFactory keyManagerFactory = KeyManagerFactory
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(store, KEYSTORE_PASSWORD.toCharArray());
// initialize trust manager factory
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(store);
clientKeyManager = keyManagerFactory.getKeyManagers()[0];
clientTrustManager = trustManagerFactory.getTrustManagers()[0];
ftpsClient.setKeyManager(clientKeyManager);
ftpsClient.setTrustManager(clientTrustManager);
String auth = getAuthValue();
if (auth != null) {
ftpsClient.setAuthValue(auth);
if(auth.equals("SSL")) {
// SSLv3 is disabled by default on the JBM JDK, therefore we need to enable it
ftpsClient.setEnabledProtocols(new String[]{"SSLv3"});
}
}
return ftpsClient;
}
示例4: createClient
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
private FTPSClient createClient() throws FileSystemException
{
final GenericFileName rootName = getRoot();
UserAuthenticationData authData = null;
try
{
authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpsFileProvider.AUTHENTICATOR_TYPES);
char[] userName = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
UserAuthenticatorUtils.toChar(rootName.getUserName()));
char[] password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
UserAuthenticatorUtils.toChar(rootName.getPassword()));
return FtpsClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), userName, password,
rootName.getPath(), getFileSystemOptions(), connectTimeout);
}
finally
{
UserAuthenticatorUtils.cleanup(authData);
}
}
示例5: getFtpsClient
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
private FTPSClient getFtpsClient() throws FileSystemException
{
if (ftpClient == null)
{
ftpClient = createClient();
FtpsDataChannelProtectionLevel level = FtpsFileSystemConfigBuilder.getInstance().getDataChannelProtectionLevel(fileSystemOptions);
if (level != null) {
try {
ftpClient.execPBSZ(0);
ftpClient.execPROT(level.name());
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
return ftpClient;
}
示例6: testStoreWithProtPAndReturnToProtCInActiveMode
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
public void testStoreWithProtPAndReturnToProtCInActiveMode()
throws Exception {
((FTPSClient) client).execPROT("P");
assertTrue(getActiveSession().getDataConnection().isSecure());
client.storeFile(TEST_FILE1.getName(), new ByteArrayInputStream(
TEST_DATA));
assertTrue(TEST_FILE1.exists());
assertEquals(TEST_DATA.length, TEST_FILE1.length());
// needed due to bug in commons-net
client.setServerSocketFactory(null);
((FTPSClient) client).execPROT("C");
client.storeFile(TEST_FILE2.getName(), new ByteArrayInputStream(
TEST_DATA));
assertTrue(TEST_FILE2.exists());
assertEquals(TEST_DATA.length, TEST_FILE2.length());
}
示例7: testReceiveEmptyFile
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
public void testReceiveEmptyFile() throws Exception {
client.enterLocalPassiveMode();
((FTPSClient) client).execPROT("P");
assertTrue(getActiveSession().getDataConnection().isSecure());
File file = new File(ROOT_DIR, "foo");
file.createNewFile();
InputStream is = null;
try {
is = client.retrieveFileStream(file.getName());
assertEquals(-1, is.read(new byte[1024]));
} finally {
IoUtils.close(is);
}
}
示例8: secureClientDataConnection
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
private void secureClientDataConnection() throws NoSuchAlgorithmException,
KeyManagementException {
// FTPSClient does not support implicit data connections, so we hack it ourselves
FTPSClient sclient = (FTPSClient) client;
SSLContext context = SSLContext.getInstance("TLS");
// these are the same key and trust managers that we initialize the client with
context.init(new KeyManager[] { clientKeyManager },
new TrustManager[] { clientTrustManager }, null);
sclient.setSocketFactory(new FTPSSocketFactory(context));
SSLServerSocketFactory ssf = context.getServerSocketFactory();
sclient.setServerSocketFactory(ssf);
// FTPClient should not use SSL secured sockets for the data connection
}
示例9: createFTPClient
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
@Override
protected FTPSClient createFTPClient() throws Exception {
FTPSClient client = new FTPSClient(useImplicit());
client.setNeedClientAuth(true);
KeyStore ks = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream(FTPCLIENT_KEYSTORE);
ks.load(fis, KEYSTORE_PASSWORD.toCharArray());
fis.close();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
.getDefaultAlgorithm());
kmf.init(ks, KEYSTORE_PASSWORD.toCharArray());
client.setKeyManager(kmf.getKeyManagers()[0]);
return client;
}
示例10: login
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
public void login(String host, String user, String pw, boolean secure) throws Exception {
if(secure) client = new FTPSClient(true);
else client = new FTPClient();
client.connect(host);
boolean success = client.login(user, pw);
if(!success) {
throw new IOException("FTP login failed, host: "+host+", user: "+user);
}
client.setFileType(FTPClient.BINARY_FILE_TYPE);
loginDir = client.printWorkingDirectory();
CTinfo.debugPrint("FTP login, u: "+user+", pw: "+pw+", loginDir: "+loginDir);
}
示例11: createRegistry
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
jndi.bind("ftpsClient", new FTPSClient("SSL"));
jndi.bind("ftpsClientIn", new FTPSClient("SSL"));
return jndi;
}
示例12: ftpConnect
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
@Override
protected FTPClient ftpConnect() throws IOException {
FilePathItem fpi = getFilePathItem();
FTPClient f = new FTPSClient();
f.connect(fpi.getHost());
f.login(fpi.getUsername(), fpi.getPassword());
return f;
}
示例13: getPathToDomainRoot
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
/**
* Determines path on FTP server to domain root
*
* @param ftp
* @param connectionInfo
* @return "" if user user, or "/<DOMAIN>/" if user is SuperAdmin or has multi-domain access
* @throws java.io.IOException
*/
private static String getPathToDomainRoot(FTPSClient ftp, SocrataConnectionInfo connectionInfo) throws IOException {
String pathToDomainRoot = "";
System.out.println("Obtaining login role - ftp.listFiles(" + FTP_REQUEST_ID_FILENAME + ")");
FTPFile[] checkRequestIdFile = ftp.listFiles(FTP_REQUEST_ID_FILENAME);
if(checkRequestIdFile.length == 0) { // user is a SuperAdmin or has multi-domain access
String domainWithoutHTTP = connectionInfo.getUrl().replaceAll("https://", "");
domainWithoutHTTP = domainWithoutHTTP.replaceAll("/", "");
pathToDomainRoot = "/" + domainWithoutHTTP;
}
return pathToDomainRoot;
}
示例14: setFTPRequestId
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
/**
* Sets (and returns) the FTP requestId to be a random 32 character hexidecimal value
*
* @param ftp authenticated ftps object
* @param pathToRequestIdFile bsolute path on FTP server where requestId file is located
* @return requestId that was set or if there was an error return error message in the
* form 'FAILURE:...'
* @throws java.io.IOException
*/
private static String setFTPRequestId(FTPSClient ftp, String pathToRequestIdFile) throws IOException {
String requestId = Utils.generateRequestId();
InputStream inputRequestId = new ByteArrayInputStream(requestId.getBytes("UTF-8"));
System.out.println("Setting job request ID - ftp.storeFile(" + pathToRequestIdFile + ", " + inputRequestId + ")");
if (!ftp.storeFile(pathToRequestIdFile, inputRequestId)) {
return FAILURE_PREFIX + ": " + ftp.getReplyString();
}
inputRequestId.close();
return requestId;
}
示例15: recordDataSyncVersion
import org.apache.commons.net.ftp.FTPSClient; //导入依赖的package包/类
/**
* Records the DataSync version of this JAR/code (for tracking purposes). If setting the version
* fails just print a message and do nothing else.
*
* @param ftp authenticated ftps object
* @param pathToDataSyncVersionFile absolute path on FTP server where 'datasync-version' file is located
*/
private static void recordDataSyncVersion(FTPSClient ftp, String pathToDataSyncVersionFile) {
try {
String currentDataSyncVersion = VersionProvider.getThisVersion();
System.out.println("Recording DataSync version being used (" + currentDataSyncVersion + ")");
InputStream inputDataSyncVersion = new ByteArrayInputStream(currentDataSyncVersion.getBytes("UTF-8"));
System.out.println("Setting job request ID - ftp.storeFile(" + pathToDataSyncVersionFile + ", " + inputDataSyncVersion + ")");
if (!ftp.storeFile(pathToDataSyncVersionFile, inputDataSyncVersion)) {
System.out.println("Failed to record DataSync version: " + ftp.getReplyString() + " Continuing...");
}
inputDataSyncVersion.close();
} catch (Exception e) {
System.out.println("Failed to record DataSync version: " + e.getMessage() + ". Continuing...");
}
}