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

Author Message
DHarper2

Guest


<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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
You will find an example in documentation.
For scheduling, see FAQ.
_________________
Martin Prikryl
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
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. Im running win 2003 server.

Thank you for any clarity


Dan
jc

Guest


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


Anonymous wrote:
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. Im running win 2003 server.

Thank you for any clarity


Dan
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 frusterdated.

thanks

dan
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
# start
winscp.exe /console /script=my_script.txt
# end


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


-jim


dharper3 wrote:
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 frusterdated.

thanks

dan
Dan

Guest


That worked, thank you SO much!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
For automation please read FAQ.
_________________
Martin Prikryl
thinclient
[View user's profile]

Joined: 2016-08-30
Posts: 1
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

Anonymous wrote:
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
# start
winscp.exe /console /script=my_script.txt
# end


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


-jim


dharper3 wrote:
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 frusterdated.

thanks

dan
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24991
Location: Prague, Czechia
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"

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.

Use the winscp.com, not winscp.exe:
https://winscp.net/eng/docs/executables
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