Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

How to set parameters in the Dos .bat file

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
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

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:
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER

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.
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
Avatar of chokka

ASKER

@gabriel, I am testing the .bat file in the cmd as  you mentioned.  I posted the error message , only after testing the .bat file.
Avatar of chokka

ASKER

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

Avatar of chokka

ASKER

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.
Avatar of chokka

ASKER

Thanks
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/"
Good to know you got it working!