WinSCP script file works in Windows 10 but not in Windows 7 - windows

I want to automate really simple ftp transfers with WinSCP (Example script file shown below. The real file would handle many files, but all simple stuff.)
open ftp://username:password#ftp.site.com/
option confirm off
cd remotedirectory
get file.csv
close
exit
A batch file containing:
winscp.com /script="staging get.txt"
opens a command prompt window and executes correctly in Windows 10, but in Windows 7 the command window opens and then immediately closes, and no files are transferred. WinSCP is in the path in both environments. I assume that a parameter or command is missing from one or the other file, but I don't know what it would be.

I was making a couple of small syntax errors. I couldn't see them because the command prompt window closed almost immediately, but the log file showed me what was happening and it was easy to fix. The lesson is - always create a log file.

Related

.bat file runs other .bat file unexpectedly [duplicate]

This question already has answers here:
What's the relative order with which Windows search for executable files in PATH?
(3 answers)
Closed 3 years ago.
I created the following TcpConn.bat script that gets the information on open tcp connections from an android device, with an interval of two seconds, running in the adb shell.
:startTCP
adb shell cat /proc/net/tcp
timeout /t 2
goto startTCP
When testing this in my /dev/test/ folder the script ran as expected and gave me the expected output of sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode.
However when I moved it to my /dev/batchFiles/ folder it started running the contents of a different .bat script in that folder (called adb.bat). with the contents
cd C:\Android\sdk\platform-tools
adb logcat -s Unity PackageManager dalvikvm DEBUG
Now in my TcpConn.bat script I execute "adb shell...", which matches the name of "adb.bat" without the extension, so it seems to make a call to this.
My question is though, why would it execute that script? I don't want it to execute the script, but run the adb command
I'm not:
providing the complete filepath/filename (which would be c:/dev/batchFiles/adb.bat), nor am I using it as a string like "adb"
I'm not using call as explained here
not using start
Do batch scripts always check the directory for a file matching part of a command and run that file, even if it doesn't have an extension appended to it? If so is there a way to disable this behaviour?
I'm aware I can just rename the "adb.bat" file and be done with it. But want to know why it gets run.
The only thing i could somewhat related to this is "How to run batch script without using *.bat extension"
As long as there is a batch file in the same directory as the one you are executing then it will execute that adb.bat file because the windows command prompt will look in the current directory first in search of an executable when you tell your batch file to execute a command.
As far as a solution to your problem I would say if it is possible then change the name of your adb.bat file to something else like adbFile.bat that way you won't be calling it every time you need to call your adb tools from that specific directory.

Opening Cygwin with Windows bat file and running script file

I require a tunnel between my windows machine to a UNIX server and wish to automate the process so that on startup the tunnel will be generated for me.
I installed Cygwin with ssh and autossh to connect to the remote server, built up the connection manually, and have confirmed that the connection works. The process involves 3 commands, which isn't a lot but something that would be great to have automated.
After creating a .sh script file, which includes my autossh connection commands, and saving it using Notepad ++ as a UNIX document (to avoid any potential conflicts regarding the file ending), I can navigate to this script in Cygwin and call bash script.sh. After which the connection is made and I can work on my server.
My problem comes when creating my bat file:
start /d "C:\cygwin\bin\" mintty.exe "C:\Users\user\Documents\Dev\" script.sh
The first part up to and including the .exe file works to open the Cygwin window, but I have been unsuccessful in feeding the script into it. I even tried including a --bash command before referencing the script file as follows, but I received an error that the command is unknown:
start /d "C:\cygwin\bin\" mintty.exe --bash "C:\Users\andrew\Documents\Development\" tunnel.sh
Does anyone know if and how it is possible to open a Cygwin window and call a script file within this window? This is my first time creating a bat file, so I hope this is perhaps a newbie problem that no one even bothers to post a solution online for...
you don't need start.
assuming your Cygwin is in C:\cygwin
you need just:
chdir c:\cygwin\bin
mintty /usr/bin/bash -l -c /cygdrive/c/Users/user/Documents/Dev/script.sh

Running a batch file through command prompt - system cannot find the path specified

I am trying to uninstall Oracle on this Windows 7 (64 bit) machine by downloading a standalone tool from Oracle, I need to run a batch file that is supposed to uninstall but I am unable to run it.
I tried to open command prompt as administrator and I am trying to run this as below:
As you can clearly see from the screenshot, I am doing a "dir" on the directory and can clearly see the file right there. Not sure what's going on here.
I also tried to run the batch file by double clicking from Windows Explorer and a terminal window opens and closes quickly but the batch file is not doing what it is supposed to do (it is clearly not executing from Windows Explorer).
Can anyone help me with this?
As theB pointed out above in a comment, this worked for me:
Open the bat file in notepad. I'll bet it starts with #echo off, and
that the error is actually coming from inside the batch file. The
error if the batch file itself wasn't found is 'X' is not recognized
as an internal or external command, operable program or batch file
'Run as Administrator' changes the current directory. See my answer here
Difference between "%~dp0" and ".\"?

Batch file/command to start a program through command line

I have a program which I want to start using the command prompt and at the same time I want to pass 2 parameters to it.
So, for example, when I wanted to start my program I would open the command prompt (in XP: start > run, type cmd, press return) and then type:
c:\rand\anotherfolder\myprogram.exe 10 20
Since I know nothing about batch files, I'm asking two things:
Can I create a batch file to automatize this process?
If yes, how :D?
I'll edit this if you respond to my comment but if you want to simply execute this command via a batch file (and you know nothing about batch files):
Open a text editor (e.g.Notepad)
Type in your command (e.g. c:\rand\aotherfolder\myprogram.exe 10 20)
Save the file as mybatchfile.cmd
Double click the file (in Windows Explorer etc.)

How to create and execute a file full of commands on Windows command prompt?

Example:
In Linux we can put the desired commands in a file and give it executable permissions. This helps us to actually run the file on the terminal and thus all the commands inside the file get automatically executed.
How to achieve this on Windows XP?
Same thing, but it's called a batch file, extension is .bat. You can also double-click to run these. This site is a great resource.

Resources