?
Solved

How to set parameters in the Dos .bat file

Posted on 2014-09-29
10
Medium Priority
?
390 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
[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
  • 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

719 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