<commit_before>/*
 * Copyright 2002-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs.provider.ftp;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.util.UserAuthenticatorUtils;

import java.io.IOException;

/**
 * Create a FtpClient instance
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision$ $Date$
 */
public class FtpClientFactory
{
    private FtpClientFactory()
    {
    }

    /**
     * Creates a new connection to the server.
     */
    public static FTPClient createConnection(String hostname, int port, char[] username, char[] password, String workingDirectory, FileSystemOptions fileSystemOptions) throws FileSystemException
    {
        // Determine the username and password to use
        if (username == null)
        {
            username = "anonymous".toCharArray();
        }

        if (password == null)
        {
            password = "<PASSWORD>".toCharArray();
        }

        try
        {
            final FTPClient client = new FTPClient();

            String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
            if (key != null)
            {
            	FTPClientConfig config = new FTPClientConfig(key);
            	
            	String serverLanguageCode = FtpFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
            	if (serverLanguageCode != null)
            	{
            		config.setServerLanguageCode(serverLanguageCode);
            	}
            	String defaultDateFormat = FtpFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
            	if (defaultDateFormat != null)
            	{
            		config.setDefaultDateFormatStr(defaultDateFormat);
            	}
            	String recentDateFormat = FtpFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
            	if (recentDateFormat != null)
            	{
            		config.setRecentDateFormatStr(recentDateFormat);
            	}
            	String serverTimeZoneId = FtpFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
            	if (serverTimeZoneId != null)
            	{
            		config.setServerTimeZoneId(serverTimeZoneId);
            	}
            	String[] shortMonthNames = FtpFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
            	if (shortMonthNames != null)
            	{
            		StringBuffer shortMonthNamesStr = new StringBuffer(40);
            		for (int i = 0; i<shortMonthNames.length; i++)
            		{
            			if (shortMonthNamesStr.length()>0)
            			{
            				shortMonthNamesStr.append("|");
            			}
            			shortMonthNamesStr.append(shortMonthNames[i]);            			
            		}
            		config.setShortMonthNames(shortMonthNamesStr.toString());
            	}
            	
            	client.configure(config);
            }
            
            FTPFileEntryParserFactory myFactory = FtpFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
            if (myFactory != null)
            {
                client.setParserFactory(myFactory);
            }

            try
            {
                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(
					UserAuthenticatorUtils.toString(username),
					UserAuthenticatorUtils.toString(password)))
                {
                    throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, username}, null);
                }

                // Set binary mode
                if (!client.setFileType(FTP.BINARY_FILE_TYPE))<commit_msg>fixed error message<commit_after>/*
 * Copyright 2002-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.vfs.provider.ftp;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.util.UserAuthenticatorUtils;

import java.io.IOException;

/**
 * Create a FtpClient instance
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Revision$ $Date$
 */
public class FtpClientFactory
{
    private FtpClientFactory()
    {
    }

    /**
     * Creates a new connection to the server.
     */
    public static FTPClient createConnection(String hostname, int port, char[] username, char[] password, String workingDirectory, FileSystemOptions fileSystemOptions) throws FileSystemException
    {
        // Determine the username and password to use
        if (username == null)
        {
            username = "anonymous".toCharArray();
        }

        if (password == null)
        {
            password = "anonymous".toCharArray();
        }

        try
        {
            final FTPClient client = new FTPClient();

            String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
            if (key != null)
            {
            	FTPClientConfig config = new FTPClientConfig(key);
            	
            	String serverLanguageCode = FtpFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
            	if (serverLanguageCode != null)
            	{
            		config.setServerLanguageCode(serverLanguageCode);
            	}
            	String defaultDateFormat = FtpFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
            	if (defaultDateFormat != null)
            	{
            		config.setDefaultDateFormatStr(defaultDateFormat);
            	}
            	String recentDateFormat = FtpFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
            	if (recentDateFormat != null)
            	{
            		config.setRecentDateFormatStr(recentDateFormat);
            	}
            	String serverTimeZoneId = FtpFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
            	if (serverTimeZoneId != null)
            	{
            		config.setServerTimeZoneId(serverTimeZoneId);
            	}
            	String[] shortMonthNames = FtpFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
            	if (shortMonthNames != null)
            	{
            		StringBuffer shortMonthNamesStr = new StringBuffer(40);
            		for (int i = 0; i<shortMonthNames.length; i++)
            		{
            			if (shortMonthNamesStr.length()>0)
            			{
            				shortMonthNamesStr.append("|");
            			}
            			shortMonthNamesStr.append(shortMonthNames[i]);            			
            		}
            		config.setShortMonthNames(shortMonthNamesStr.toString());
            	}
            	
            	client.configure(config);
            }
            
            FTPFileEntryParserFactory myFactory = FtpFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
            if (myFactory != null)
            {
                client.setParserFactory(myFactory);
            }

            try
            {
                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(
					UserAuthenticatorUtils.toString(username),
					UserAuthenticatorUtils.toString(password)))
                {
                    throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, UserAuthenticatorUtils.toString(username)}, null);
                }

                // Set binary mode
                if (!client.setFileType(FTP.BINARY_FILE_TYPE))
{'fraction_non_alphanumeric': 0.08815735833673054, 'fraction_numerical': 0.003261312678353037, 'mean_word_length': 2.1716224951519068, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4044639', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2479, 'n_words': 527}