Search code examples
batch-filefile-iosshsftp

psftp.exe get files from the server and delete


I'm using psftp.exe to download files from the server. Is there an easy way to delete these files once I have downloaded them but leave the new ones that might have appeared on the server when I was downloading to be downloaded next time?

Here's my command line:

psftp.exe domain.com -i keys\private.ppk
get *.xml

Edit: I want to download the files from a Linux box to a Windows PC.


Solution

  • There's no easy way to do this with psftp. You would have to parse its output to find files that were successfully downloaded.


    Though you can do this easily with WinSCP. Just use get -delete *.xml command.

    Full WinSCP script would be:

    open sftp://domain.com/ -privatekey=keys\private.ppk -hostkey=...
    get -delete *.xml
    exit
    

    See an introduction to WinSCP scripting.

    See also a guide for converting PSFTP script to WinSCP.

    You can also have WinSCP GUI generate script like this for you.

    (I'm the author of WinSCP)