Need to build a batch file to send files sFTP via winscp

Advertisement

DHarper2
Guest

Need to build a batch file to send files sFTP via winscp

<Moved from Documentation Forum...DUH!>

Hi-
I am a mac java guy transitioning to windows / .net.
I need to automate the sending of a file via winSCP. I have it set up on my windows 2003 server and can drag and drop via the GUI. However, I need to send a file on a weekly basis from sql2005. Can someone point me to a batch file 'how to' to walk me through building a .bat file? I am assuming I can then schedule the bat file to fire off at the desired time via scheduled events in windows. Bonus points for any scripts that can fire off a bat file from asp.net.

TIA

Dan

Reply with quote

Advertisement

Guest

Thanks, tried that one, no luck.
I was just wondering if anyone had a batch file they could cut and paste so I could take a look at the code.

thanks

Dan

Reply with quote

Guest

Ok, let me ask it this way.
If I save the following file in a .bat file and run it, shouldn't it work?
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
open myuserName:MyPassword@myftpserver.net:22 (DO I need :22 here?)
# Change remote directory
cd /usr/home/ftpaccts/MyDirectory/
# Force binary mode transfer
option transfer binary
# Download file to the local directory
get TestFile.txt C:\Documents and Settings\Administrator\Desktop\DATA_IN
# Disconnect
close
exit
-OR- Asked another way, if I set up windows scheduled event to fire up WinSCP, WHERE do I add the code to run the get and put? I only have a place for putting comments in the scheduled task. I'm running Windows 2003 server.

Thank you for any clarity

Dan

Reply with quote

jc
Guest

winscp bat file

The script that you listed is to be interpreted by winscp. In the documentation

https://winscp.net/eng/docs/scripting

this script is named example.txt see the two examples at the bottom of the docs page to see the command line syntax for using the script.

Open a shell window, at the command prompt experiment with these commands and options and when you find the right command/syntax to accomplish the task from the command line, put that code into your bat file.

Good Luck,
-jc

Reply with quote

Advertisement

dharper3
Guest

Thanks!
I got some scripts running using command line and winscp.com
Question: What does the batch file look like?
C:\Program Files\WinSCP\winscp.com
open MyUserName:MyPassword@MySFTPserver.net
get TestFile.txt c:\
close
exit
will not work, but it will in command line.

I am so close, so tired, so frustrated.

thanks

dan

Reply with quote

Guest

Put the individual steps into your script file.

For example: my_script.txt contains the following
# start script code
open MyUserName:MyPassword@MySFTPserver.net
option transfer binary
get TestFile.txt c:\
close
# end script
put my_script.txt in the same folder as winscp.exe

You should now be able to use the script to ftp
promp> winscp.exe /console /script=my_script.txt
if this works okay then all your bat file needs to have in it is the above command.

my_ftp.bat contains
winscp.exe /console /script=my_script.txt

When you run my_ftp.bat all it does is executes the command with options you've included.

-jim

Reply with quote

Advertisement

thinclient
Joined:
Posts:
1

Any way to show script progress in dos window, when runing a .bat that calls a script file?

I would like to see the results of the script in dos prompt but when I launch the batch file from DOS prompt it connects, calls the script, which sftp's the file into the directory. It works, but all I see in the DOS prompt is this:
"C:\Program Files (x86)\WinSCP\WinSCP.exe"
/log="C:\Logs\WinSCP.log"
/ini=nul /command
/script="C:\Script.txt"
And I would like to see the script running e.g. if script has a command dir I'd see a directory listing output to DOS prompt.

Thanks,
thinclient

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Any way to show script progress in dos window, when runing a .bat that calls a script file?

thinclient wrote:

I would like to see the results of the script in dos prompt but when I launch the batch file from DOS prompt it connects, calls the script, which sftp's the file into the directory. It works, but all I see in the DOS prompt is this:
"C:\Program Files (x86)\WinSCP\WinSCP.exe"
/log="C:\Logs\WinSCP.log"
/ini=nul /command
/script="C:\Script.txt"
...
Use the winscp.com, not winscp.exe:
https://winscp.net/eng/docs/executables

Reply with quote

Advertisement

You can post new topics in this forum