Not able to copy files from one to other folder in SFTP server

Hi, I am new to UiPath and I need to automate copying of ETL data files from one to other folder after login to SFTP server. These both folders source and target are in SFTP server and not in my local. Kind of simple UNIX copy command but it is not working. I tried copy, move etc activites. I also tried assign but on providing server file path, the error shows it is trying to look at provided path in C drive and not in SFTP server.
Appreciate any pointers on which exact activity to use for this.
Thanks,
Subbu

Hi @subhashmanocha1,

Check this if this helps.

Regards
Sonali

Hi @subhashmanocha1

Can you try with FTP activities

Make sure to download the packageUipath.FTP.Activities


Check on SFTP

Hope this helps!

I shall retry, but using FTP activities I am able to connect to SFTP server and validated root folder exists. My next steps are to

  1. Navigate to source folder which I would manually do by cd
  2. Copy files from source to target which I use manually by command cp * .
    The error I am getting is – Folder does not exist - It is somehow checking the server path/folder in my C drive.
    Appreciate any pointers on how to automate steps 1, 2 above and resolve this error.
    Thanks,
    Subbu

Thanks for prompt response. Please see my reply to Sanjay and suggest what am I missing.
Subbu.

@subhashmanocha1

Have you checked the thread I shared, there is a xaml solution in there, may be have a look and see how its done in that one.

Yes I checked test-ftp.xaml
It does not have steps of navigating to source file folder and then copying file to a second/destination file folder. Moreover in my system installed Studio, it does not find activity by name “with FTP”. Here are my steps again, those I am able to do manually but trying to accomplish this using FTP activity package in UiPath. The file copy actions are to be done on SFTP server folders and nothing in local. Both folders are on same server.

  1. Connect to SFTP server
  2. Verify root folder exists
  3. Navigate or changeDirectory to sourceFileFolder.
  4. Run command to Copy all files from sourceFileFolder to targetFileFolder
  5. Verify the filecopy was successful.

Thanks,
Subhash Manocha

@subhashmanocha1

Import these namespaces

1. Renci.SshNet
2. Renci.SshNet.Common
3. Renci.SshNet.Sftp

Use invoke code
Note: LLM helped me to write this it is verified by me

Try
    Using sftp As New SftpClient(ftpServer, ftpPort, ftpUsername, ftpPassword)
        sftp.Connect()
        Console.WriteLine("Connected to SFTP Server")

        ' 1. Verify root folder exists
        If Not sftp.Exists("/") Then
            Throw New Exception("Root folder does not exist.")
        End If

        ' 2. Define source and target folders
        Dim sourceFolder As String = "/sourceFileFolder"
        Dim targetFolder As String = "/targetFileFolder"

       

       

        ' 5. List all files in the source folder
        Dim sourceFiles = sftp.ListDirectory(sourceFolder).
            Where(Function(f) Not f.IsDirectory AndAlso Not f.Name.StartsWith("."))

        ' 6. Copy each file to the target folder
        For Each file In sourceFiles
            Dim sourcePath As String = file.FullName
            Dim targetPath As String = targetFolder & "/" & file.Name

            Console.WriteLine("Copying file: " & file.Name)

            ' Read from source
            Using sourceStream As Stream = sftp.OpenRead(sourcePath)
                ' Upload to target
                sftp.UploadFile(sourceStream, targetPath)
            End Using

            ' 7. Verify copy
            If sftp.Exists(targetPath) Then
                Console.WriteLine("File copied: " & file.Name)
            Else
                Console.WriteLine("Failed to copy file: " & file.Name)
            End If
        Next

        sftp.Disconnect()
        Console.WriteLine("SFTP file copy process completed.")

    End Using
Catch ex As Exception
    Console.WriteLine("Error: " & ex.Message)
End Try

Make sure to replace the values
targetFileFolder, sourceFileFolder, ftpPassword, ftpUsername, ftpPort, ftpServer in the code

Do mark it as a solution if it helps you!
Happy learning :innocent: