chokka
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.
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/"
D--Ups.SalesApps.Net-ShellScript-TestUpl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
c:\> script.bat UserName Password
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.
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.
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.
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.
ASKER
Thanks
Try:
Set SRC="%1"
Set DST="sftp://%2:%3@%4:%5//DestinationFolderhome/DestinationSubFolder/DestinationSubFolder/"
D:\MyProject\ShellScript>T est.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 "@"hostnam e":22//Des tinationFo lderhome/D estination SubFolder/ Destinatio nSubFolder /"
Set SRC="%1"
Set DST="sftp://%2:%3@%4:%5//DestinationFolderhome/DestinationSubFolder/DestinationSubFolder/"
D:\MyProject\ShellScript>T
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
Good to know you got it working!
Example, change
Set SRC="D:\CSV\Test.csv"
to
Set /p SRC=Enter source file: