Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set parameters in the Dos .bat file

Posted on 2014-09-29
10
Medium Priority
?
391 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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

824 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