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

Author Message
othmane

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
See http://winscp.net/eng/docs/library_example_moves_files_keeping_directory_structure
othmane

Guest




Thank you,

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

Code:
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]
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License