Solved

How can I script WinSCP to create a directory for the current date and then post files to that folder?

Posted on 2008-10-17
7
5,037 Views
Last Modified: 2012-08-14
We have a need to post files via WinSCP daily (approx 1,000-1,200 files).  How do we have WinSCP create a folder for the current date then put the files to that folder?

Here is what we are working from:

# 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
# open user:password@example.com
# Connect using a password
# Connect
open user:password@example.com
# Change remote directory      
cd /home/
# Force binary mode transfer
option transfer binary
# Upload current file to working directory
put *.xml
# Download file to the local server and place in SFTP2WIN directory
get *.xml SFTP2WIN\*.xml
# Disconnect
close
# Exit WinSCP
exit

Very simple and straight forward.  Put I need the batch of files put into a separate directory daily based on the date.

Many thanks for you help,

matt
0
Comment
Question by:TX_SCUBA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 38

Expert Comment

by:Shift-3
ID: 22745276
You can use a batch script to create a WinSCP script on the fly and then execute it.

Paste the script below into a text file with a .cmd extension.  Running it will generate and execute a script named example.txt with the specified commands.  If you would like to use a different date format than yyyymmdd or you use Regional Options other than English (United States), please specify the format and what output you get when you run echo %date% at the command prompt.


@echo off
setlocal
 
set folder=%date:~10,4%%date:~4,2%%date:~7,2%
set script=example.txt
 
if exist "%script%" del "%script%"
 
echo option batch on >> "%script%"
echo option confirm off >> "%script%"
echo open user:password@example.com >> "%script%"
echo cd /home/ >> "%script%"
echo mkdir %folder% >> "%script%"
cd %folder% >> "%script%"
echo option transfer binary >> "%script%"
echo put *.xml >> "%script%"
echo get *.xml SFTP2WIN\*.xml >> "%script%"
echo close >> "%script%"
echo exit >> "%script%"
 
winscp.exe /console /script="%script%"

Open in new window

0
 

Author Comment

by:TX_SCUBA
ID: 22754262
Shift
The mkdir command or mk / md are not supported.  Any other ideas?

Thx,
matt
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22754289
Hm, that ought to be pretty standard.  Are you sure there isn't a permissions issue?  

Can you create a directory in an interactive FTP session?  If so, what commands do you use?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:TX_SCUBA
ID: 22754491
Can only use a SFTP client to connect with.  I can create a folder using the GUI, by right clicking and selecting new directory.

Get unknown command with MK or MKDIR.

The CMD you wrote rocks!

~
0
 

Author Comment

by:TX_SCUBA
ID: 22754548
Disregard...

It seems as though the sesson has bumped me back to the command line.

Working to see if the rest of the script works.

~
0
 

Author Comment

by:TX_SCUBA
ID: 22754657
Ok now I am getting an Error code 14 and the directory is not being created on the server.

~
0
 

Author Closing Comment

by:TX_SCUBA
ID: 31507204
Worked like a charm once I removed the space at the end of the mkdir 20081919 line in the file and removed the folder that had already been created.

Many thanks Shift-3

matt
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question