<commit_before>mv_file = "test_mv.txt"
tempfile(mv_file)

opts = (
    :hostname => hostname(server),
    :username => username(server),
    :password => password(server),
    :ssl => false,
)

function no_unexpected_changes(ftp::FTP, hostname::AbstractString=hostname(server))
    other = FTP(; opts...)
    @test ftp.ctxt.options == other.ctxt.options
    @test ftp.ctxt.url == "ftp://$hostname/"
    close(other)
end

function expected_output(active::Bool)
    mode = active? "active":"passive"
    expected = """
        Host:      ftp://$(hostname(server))/
        User:      $(username(server))
        Transfer:  $mode mode
        Security:  None

        """

    buff = IOBuffer()
    ftp = FTP(; opts..., active_mode=active)
    println(buff, ftp)
    seekstart(buff)
    @test readstring(buff) == expected
    close(ftp)
end

# check connection error
@test_throws FTPClientError FTP(hostname="not a host", username=username(server), password=password(server), ssl=false)

# check object
ftp = FTP(; opts...)
no_unexpected_changes(ftp)
close(ftp)

# check readdir
ftp = FTP(; opts...)
server_dir = readdir(ftp)
@test contains(string(server_dir), "test_directory")
@test contains(string(server_dir), "test_byte_file")
@test contains(string(server_dir), "test_download.txt")
no_unexpected_changes(ftp)
close(ftp)

# check download to buffer
ftp = FTP(; opts...)
buffer = download(ftp, download_file)
@test readstring(buffer) == readstring(joinpath(ROOT,download_file))
no_unexpected_changes(ftp)
close(ftp)

# check upload
ftp = FTP(; opts...)
local_file = upload_file
server_file = joinpath(ROOT, local_file)
tempfile(local_file)
@test isfile(local_file)
resp = upload(ftp, local_file)
@test isfile(server_file)
@test readstring(server_file) == readstring(local_file)

no_unexpected_changes(ftp)
close(ftp)
cleanup_file(server_file)

# check mkdir
ftp = FTP(; opts...)<commit_msg>accounting for change in testing order<commit_after>mv_file = "test_mv.txt"
tempfile(mv_file)

opts = (
    :hostname => hostname(server),
    :username => username(server),
    :password => password(server),
    :ssl => false,
)

function no_unexpected_changes(ftp::FTP, hostname::AbstractString=hostname(server))
    other = FTP(; opts...)
    @test ftp.ctxt.options == other.ctxt.options
    @test ftp.ctxt.url == "ftp://$hostname/"
    close(other)
end

function expected_output(active::Bool)
    mode = active? "active":"passive"
    expected = """
        Host:      ftp://$(hostname(server))/
        User:      $(username(server))
        Transfer:  $mode mode
        Security:  None

        """

    buff = IOBuffer()
    ftp = FTP(; opts..., active_mode=active)
    println(buff, ftp)
    seekstart(buff)
    @test readstring(buff) == expected
    close(ftp)
end

# check connection error
@test_throws FTPClientError FTP(hostname="not a host", username=username(server), password=password(server), ssl=false)

# check object
ftp = FTP(; opts...)
no_unexpected_changes(ftp)
close(ftp)

# check readdir
ftp = FTP(; opts...)
server_dir = readdir(ftp)
@test contains(string(server_dir), "test_directory")
@test contains(string(server_dir), "test_download.txt")
no_unexpected_changes(ftp)
close(ftp)

# check download to buffer
ftp = FTP(; opts...)
buffer = download(ftp, download_file)
@test readstring(buffer) == readstring(joinpath(ROOT,download_file))
no_unexpected_changes(ftp)
close(ftp)

# check upload
ftp = FTP(; opts...)
local_file = upload_file
server_file = joinpath(ROOT, local_file)
tempfile(local_file)
@test isfile(local_file)
resp = upload(ftp, local_file)
@test isfile(server_file)
@test readstring(server_file) == readstring(local_file)

no_unexpected_changes(ftp)
close(ftp)
cleanup_file(server_file)

# check mkdir
ftp = FTP(; opts...)
{'fraction_non_alphanumeric': 0.14384656366542356, 'fraction_numerical': 0.0, 'mean_word_length': 4.612855007473842, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6770905', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1262, 'n_words': 271}