Search code examples
windowsbashbatch-fileftpwinscp

Have .bat display info during execution (of WinSCP)


Before I start I want to say thank you in advance for any help provided. This is my first post and I have tried to follow the rules. I checked but couldn't find this answered anywhere.

I have a batch file that I have set to run at a scheduled time daily. The file uses WinSCP to grab the contents of a folder on a server and copies them to a local directory. The size of the transfer is about 1.2GB - 1.5GB and takes about 20 seconds. I would like to display some information while the transfer happens. I'm looking for a way to display the bytes per second going over my network interface (or similar) in the same cmd window as the transfer.

I figured out how to get the info I want to display by doing:

typeperf "\Network Interface(Realtek PCIe GbE Family Controller)\Bytes Received/sec"

I'm just wondering if there is a way to display the information that is returned from the typeperf command while my file transfer completes. Then, at the end of the transfer have the window close. Sort of like some text that says "Please Wait" while the program runs except it would show bytes/sec over the interface.

Here is my script i use for the WinSCP FTP transfer with the ip and username removed:

"C:\Program Files (x86)\WinSCP\WinSCP.exe" /ini=nul /command "open ftp://UserNamer:StrongPassword1@###.###.###.###/" "cd /ShooterGame/Saved" "lcd ""D:\ARK Server Backup""" "get SavedArk57057" "exit"

Looking forward to any help that can be provided, assuming what I was is actually possible.


Solution

  • WinSCP itself shows a transfer progress. Except that you run WinSCP in a hidden mode.

    Replace winscp.exe with winscp.com to display a transfer progress in a console window.

    enter image description here


    If you want to display a progress in your own custom format, use WinSCP .NET assembly [for example from a PowerShell script] instead of WinSCP scripting. And handle Session.FileTransferProgress event.

    There's a guide for converting WinSCP script to PowerShell script with use of WinSCP .NET assembly.