Download of FTP files and enumerate activity

Folks, I need help downloading several files from an FTP folder and using the enumerate activity.In the Download activity, it doesn’t give any error message, but it doesn’t download the files; when I enter the file name, I can download it.

And the enumerate activity presents the following message

@Richarlei_Reis

Please open exception details from locals panel to see the full exception

As the language is different try pasting the error here

Cheers

@Richarlei_Reis

Did you happen to give th ftp folder path itself or by chance did you give yhe filepath?

Just to make sure include a / at the end as well

Cheers

@Richarlei_Reis

This has been observed for few people..which server are you on and what files are present there?

Also if not tried already remove the trailing / as well

Cheers

Sever Windows

@Richarlei_Reis

Can you please copy the pth as is and try

Also just to verify please give obly one folder and check if it works..that way we can ruleout the possibilities..as there are issues found when there are spaces in the folderpath as wel

Cheers

I still get the error

Try this custom C# code approach

Example of ftp_remotePath content:

Studio 2024.10.12 Windows project

Dependencies:

UiPath.System.Activities.24.10.7
UiPath.FTP.Activities.2.4.0

Import these namespaces in the Studio Imports panel:

System
System.Data
System.Linq
Renci.SshNet

Add a Try Catch activity

Add an Invoke Code for C# with this code:

// Declare DataTable outside the try block for broader access
System.Data.DataTable out_dt = new System.Data.DataTable();

try
{
    // Define authentication (using password)
    var authMethod = new Renci.SshNet.PasswordAuthenticationMethod(ftp_username, ftp_password);

    // Initialize connection info with authentication
    var con = new Renci.SshNet.ConnectionInfo(ftp_hostname, ftp_port_number, ftp_username, authMethod);

    using (var client = new Renci.SshNet.SftpClient(con))
    {
        client.Connect();

       if (client.IsConnected)
        {
            var files = client.ListDirectory(ftp_remotePath);

            // Define columns for DataTable only once
            out_dt.Columns.Add("Name", typeof(string));
			out_dt.Columns.Add("FullName", typeof(string));
			out_dt.Columns.Add("IsSymbolicLink", typeof(string));
			out_dt.Columns.Add("isRegularFile", typeof(string));
			out_dt.Columns.Add("Type", typeof(string));

            foreach (var file in files)
            {
                out_dt.Rows.Add(file.Name, file.FullName, file.IsSymbolicLink, file.IsRegularFile, file.IsDirectory ? "Folder" : "File");
            }

            // Display the DataTable contents (optional)
           // Console.WriteLine("Listing Objects in Directory (Folders and Files):");
            //foreach (DataRow row in out_dt.Rows)
            //{
                //Console.WriteLine($"Name: {row["Name"]}, Type: {row["Type"]}");
            //}
        }

        client.Disconnect();
    }

    ftp_dt_ToUseInWorkflow = out_dt;
}
catch (Exception ex)
{
    Console.WriteLine($"An error occurred: {ex.Message}");
    throw; // Re-throws the caught exception
}

In the Invoked code arguments add these arguments:

Name: ftp_dt_ToUseInWorkflow → Direction: Out → Type: System.Data.DataTable → Value: out_DTResponse
Name: ftp_hostname → Direction: In → Type: System.String → Value: "ftp_hostname"
Name: ftp_username > Direction: In → Type: System.String → Value: "ftp_username"
Name: ftp_port_number > Direction: In → Type: System.Int32 → Value: ftp_port_number
Name: ftp_password → Direction: In → Type: System.String → Value: "ftp_password"
Name: ftp_remotePath → Direction: In → Type: System.String → Value: "/ftp_folder_path"

Example:

Add a For Each activity for out_dtResponse.AsEnumerable()

image

In the For Each Body add this log message for testing purposes:

"Name: " + currentDataRow("Name").ToString + vbCr + "FullName: " + currentDataRow("FullName").ToString + vbCr + "IsSymbolicLink: " + currentDataRow("IsSymbolicLink").ToString + vbCr + "isRegularFile: " + currentDataRow("isRegularFile").ToString + vbCr + "Type: " + currentDataRow("Type").ToString

Example results:

I have some errors, can you adjust my project or send me your project, I will adjust it with my data.

TESTEFTP2.zip (1.1 MB)

Test this fixed project.

You didn’t follow all the steps from the above, and that’s why you got numerous errors.

TESTEFTP2_modified.zip (1.2 MB)

It was compiled in Studio STS 2025.0.167. You can get its installer from https://download.uipath.com/UiPathStudioCloud.msi

Sorry, I’m new to UiPath.
After entering my FTP data, the following exception appeared

I changed from String to Object and got the information below.

How do I copy these files to my local computer?

Cool.

Then, you can readjust the C# code to allow also FTP file manipulation.

Can you help me with the code?

The code will look something like below:
Readapt it to by dynamic for remoteFilePath and localFilePath.

try
{
    // Define authentication (using password)
    var authMethod = new Renci.SshNet.PasswordAuthenticationMethod(ftp_username, ftp_password);

    // Initialize connection info with authentication
    var con = new Renci.SshNet.ConnectionInfo(ftp_hostname, ftp_port_number, ftp_username, authMethod);

    using (var client = new Renci.SshNet.SftpClient(con))
    {
        client.Connect();

       if (client.IsConnected)
    {
       // Specify the remote file path and the local file path
        string remoteFilePath = "/remote/path/to/file.txt";
        string localFilePath = @"C:\local\path\to\file.txt";

        // Download the file
        using (var fileStream = File.Create(localFilePath))
        {
            client.DownloadFile(remoteFilePath, fileStream);
        }
    }

        client.Disconnect();
    }

}
catch (Exception ex)
{
    Console.WriteLine($"An error occurred: {ex.Message}");
    throw; // Re-throws the caught exception
}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.