Solved

How to set parameters in the Dos .bat file

Posted on 2014-09-29
10
383 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
Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

910 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