Skip to content

Powershell - How to upload entire local directory recursively #915

Closed as not planned

Description

@philsayersCDS

FTP OS: Unix / Windows / Embedded
Windows 10 x64

FTP Server:
IIS Server 2012R2

Computer OS:
Windows 10 Pro x64

FluentFTP Version:
39.3

Framework:
PowerShell

Is it possible to use the powershell cmdlet to upload a directory recursively?
I have a folder with an unknown number of subfolders and files. It is the output from a documentation generator.
I need to basically upload the entire folder as-is to an FTP site.

I have this so far, but it seems to flatten out the folder tree completely, and all the files end up in the "Upload" folder of my ftp site:

$ListFiles = Get-ChildItem -LiteralPath "D:\MyLocalFolderWithComplexFolderSubtree" -Recurse
$Client = Connect-FTP -Server {IPADDRESS} -Verbose -Username "{USER}" -Password "{PASSWORD}" -EncryptionMode Implicit -ValidateAnyCertificate
Send-FTPFile -Client $Client -LocalPath $ListFiles.FullName -RemotePath "/Upload" -RemoteExists Overwrite
Disconnect-FTP -Client $Client

Is there a way to rework the powershell so the local folder and sub-folder structure is created in an identical fashion on the ftp site?

Activity

  1. philsayersCDS commented on Aug 30, 2022

    @philsayersCDS
    Author

    This PS script works, but it's a bit of a hack. I'm using the "Transferto" powershell module because it wraps up both FluentFTP and SSH.NET.
    https://github.com/EvotecIT/Transferetto

    I work with both FTPS and SFTP servers, so having it all wrapped in a single module just seems easier.
    I have a help doc generator that spits out a static html site.
    I needed to upload the entire local folder tree to a subfolder on a website.

    It would be nice to be able to avoid dropping down to the .Net classes/objects directly, but this works for my needs.

    This is what I ended up with:

    $ftpServer = "FTP.SERVER.IP.ADDRESS"
    $LocalFolder = "C:\SomeFolder\HelpDocsOutput"
    $FtpUser = "USER"
    $FtpPass = "PASSWORD"
    $FileFolderList = Get-ChildItem -LiteralPath "$LocalFolder" -Recurse
    
    try 
    {
    $Client = Connect-FTP -Server $ftpServer -Verbose -Username "$FtpUser" -Password "$FtpPass" -EncryptionMode Implicit
    $Client.UploadDirectory($LocalFolder, "/HelpDocs", [FluentFTP.FtpFolderSyncMode]::Mirror, [FluentFTP.FtpRemoteExists]::Overwrite, [FluentFTP.FtpVerify]::None )
    }
    catch [Exception] {
        # TODO: Add error logging /output here.
    }
    
    finally {
    Disconnect-FTP -Client $Client
    }
    
    
  2. robinrodricks commented on Sep 19, 2022

    @robinrodricks
    Owner

    Added to the bucket list. We will pick this up as and when we have free time. Comment on this issue if you want us to prioritize it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址