OpenSSH sftp
cannot do this on its own. But you can use some fancy batch file construct to select the latest file and then generate an ad-hoc sftp
upload script.
Some references:
Or use some more advanced Windows command-line SFTP client.
For example with WinSCP scripting, it's as easy as using -latest
switch in the put
command:
open sftp://username@example.com/ -privatekey=ssh.ppk
lcd E:\localpath\
cd \sftpserverpath\
ascii
put -transfer=ascii -latest *.csv
exit
Run the script (upload.txt
) like:
winscp.com /script=upload.txt /ini=nul /log=upload.log
You can even have WinSCP generate the script/batch file for you (you just need to add the -latest
switch manually).
References:
Note that WinSCP uses .ppk format of private key files. While OpenSSH sftp
uses PEM format. Even though your key file is named .ppk, it cannot be real .ppk file, otherwise the sftp
would reject it. You have probably converted original .ppk file to PEM, but incorrectly kept an original extension. You have to use the original .ppk file with WinSCP (if you do not have it, you can convert the PEM back to .ppk using PuTTYgen).
Also note that WinSCP actually supports the text/ascii mode (-transfer=ascii
), while sftp
does not (there's no ascii
command).
(I'm the author of WinSCP)