try {
SocketFactory socketFactory = (SocketFactory) Class.forName(System.getProperty("org.apache.commons.net.socketFactory")).newInstance();
client.setSocketFactory(socketFactory);
} catch(Throwable t) {
throw new FileSystemException(t);
}
}
client.connect(hostname, port);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
throw new FileSystemException("vfs.provider.ftp/connect-rejected.error", hostname);
}
// Login
if (!client.login(username, password))
{
throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, username}, null);
}
// Set binary mode
if (!client.setFileType(FTP.BINARY_FILE_TYPE))
{
throw new FileSystemException("vfs.provider.ftp/set-binary.error", hostname);
}
// Set dataTimeout value
Integer dataTimeout = FtpFileSystemConfigBuilder.getInstance().getDataTimeout(fileSystemOptions);
if (dataTimeout != null)
{
client.setDataTimeout(dataTimeout.intValue());
}
// Change to root by default
// All file operations a relative to the filesystem-root
// String root = getRoot().getName().getPath();
Boolean userDirIsRoot = FtpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(fileSystemOptions);
if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
{
if (!client.changeWorkingDirectory(workingDirectory))
{
throw new FileSystemException("vfs.provider.ftp/change-work-directory.error", workingDirectory);
}
}
Boolean passiveMode = FtpFileSystemConfigBuilder.getInstance().getPassiveMode(fileSystemOptions);
if (passiveMode != null && passiveMode.booleanValue())
{
client.enterLocalPassiveMode();
}
}
catch (final IOException e)
{
if (client.isConnected())
{
client.disconnect();
}
throw e;
}
return client;
}
catch (final Exception exc)
{
throw new FileSystemException("vfs.provider.ftp/connect.error", new Object[]{hostname}, exc);
}
}