Solved

How to set parameters in the Dos .bat file

Posted on 2014-09-29
10
381 Views
Last Modified: 2014-09-29
I am transferring a file from my local computer ( Windows ) to a Linux Server through SFTP Connection.

Input Paramters are

1) Source File
2) Destination File Path
3) SFTP : Username
4) SFTP : Password
5) SFTP : Hostname
6) SFTP : PortNumber

I have to change this Dos command inside the .bat file in such a way to accept the Input Parameters.

How to change the Dos Command.

Set SRC="D:\CSV\Test.csv"
Set ST="sftp://username:password@hostname:portnumber//DestinationFolderhome/DestinationSubFolder/DestinationSubFolder/"

Open in new window

D--Ups.SalesApps.Net-ShellScript-TestUpl
0
Comment
Question by:chokka
  • 5
  • 4
10 Comments
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40350750
If you want to accept input variables just change how your variables are set, /p will prompt for variable data.

Example, change
Set SRC="D:\CSV\Test.csv"
to
Set /p SRC=Enter source file:
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
ID: 40350756
Just add as many parameters as you need like:

%1 - Source File
%2 - Destination File Path
%3 - SFTP : Username
etc.

Set SRC=%1
Set ST="sftp://%3:password@hostname:portnumber//%2"
0
 

Author Comment

by:chokka
ID: 40350821
I set the parameter as like this

Set SRC= %1
Set DST="sftp://%2:%3@%4:%5//home/myfolder/"

Tried to call .bat from cmd.exe

I gave input parameters correctly.What could be the reason

I am getting an error message as System Could not find the file path.
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40350842
You would need to run the bat file from cmd like this if you want to run it that way:

c:\> script.bat UserName Password
0
 

Author Comment

by:chokka
ID: 40350869
@gabriel, I am testing the .bat file in the cmd as  you mentioned.  I posted the error message , only after testing the .bat file.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:chokka
ID: 40350944
When i tested only with Source Variable , it works.

When i try to add both Source and Destination variable, I am getting error.

I guess Destination Variable has issue.

Output from Command Prompt.


D:\MyProject\ShellScript>Test.bat "D:\CSV\Test.csv" "username" "password" "hostname" 22
The system cannot find the path specified.
The system cannot find the path specified.

Open in new window

0
 

Author Comment

by:chokka
ID: 40350992
I solved the problem, by passing only two variables. SourceFile variable and Sftp variable. Sftp will be combined as one string and send to the batch file as one variable.
0
 

Author Closing Comment

by:chokka
ID: 40350994
Thanks
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40351008
Try:

Set SRC="%1"
Set DST="sftp://%2:%3@%4:%5//DestinationFolderhome/DestinationSubFolder/DestinationSubFolder/"

D:\MyProject\ShellScript>Test.bat D:\CSV\Test.csv username password hostname 22

It might be the double quotes on your params that is throwing it off which would make it:
Set SRC=""D:\CSV\Test.csv""
Set DST="sftp://"username":"password"@"hostname":22//DestinationFolderhome/DestinationSubFolder/DestinationSubFolder/"
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40351011
Good to know you got it working!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now