How to use get -delete ... to delete files only and not directories

Advertisement

othmane
Guest

How to use get -delete ... to delete files only and not directories

I want a solution please of my problem..
I want to download files from FTP and make directories empty .

Example :

file0,DIR1(file1,file2,DIR2(file3 ...), ...) ---> DIR1(DIR2(empty))

thank you VERY MUCH

Reply with quote

Advertisement

othmane
Guest

Re: How to use get -delete ... to delete files only and not directories

martin wrote:


Thank you,

I found a script which gets files and deletes them after succesfull download, it keeps the local directories hierarchy by default :)

try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::ftp
        FtpSecure = [WinSCP.FtpSecure]::Implicit
        HostName = "xxxx"
        UserName = "xxxx"
        Password = "xxxxx"
        PortNumber = "990"
        FtpMode = "Passive"
        TlsHostCertificateFingerprint = "xxxxxx"
    }
 
    $session = New-Object WinSCP.Session
    $session.SessionLogPath = "x:\xxxx.log"
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Download files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
        $transferOptions.FileMask = "*"
        $transferOptions.PreserveTimestamp = $true
 
        $transferResult = $session.GetFiles("/","x:\xxxx", $False, $transferOptions)   
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host ("Download of {0} succeeded" -f $transfer.FileName)
           #$removalResult = $session.RemoveFiles($session.EscapeFileMask($transfer.FileName))
            #if ($removalResult.IsSuccess)
                #{
                    #Write-Host ("Removing of file {0} succeeded" -f
                        #$transfer.FileName)
                #}
                #else
                #{
                    #Write-Host ("Removing of file {0} failed" -f
                        #$transfer.FileName)
                #}
        }

    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}
[/code]

Reply with quote

Advertisement

You can post new topics in this forum