I am trying to figure out what is wrong in my script. I am trying to automate the task of getting data from many FTP servers, using PowerShell as scripting environment.
I am using
ftp.exe -n -s:Script.txt $SOMEIp
It was giving me output:
Connected to 10.128.10.195.
220 Service ready
User(10.128.10.195:(none)):
530 Invalid user
Login failed.
I tried some troubleshooting by experiencing with the script and so on - the initial result is that
Is the "rectangle" char appending "a" character causing this or what is exactly wrong with the script?
In any case:
admin
password
cd ...
ascii
get somefile.txt
quit
is the script, while command to execute it, as I mentioned,
ftp.exe -n -s:Script.txt $SOMEIp
On the PNG file you see some troubleshooting file, where I tried to "ignore" the first wrong line and then restart with user and password prompt.
Would be great if you could share some ideas on that matter.
Cheers
Alex
Try saving your Script.txt as ASCII or ANSI. It could be that your ftp client doesn't understand unicode.
Try changing your script to this:
user admin password
cd ..
ascii
get somefile.txt
quit
You need to tell the FTP server that what is coming is the username and password. Also, you need two dots not three to go up a level.
Related
I want to put the following into a batch file so i can convert it to a .exe and allow another user to run it on another PC.
The user does not have local admin access and has a frequent problem with their com1 port. I have installed/copied devcon to the user's PC and have gotten this script working fine without the credential change, i just need to know how i can run the batch file as a local user.
This is what i have written:
runas.exe /profile /user:localpcname\administrator /password:12345678
Devcon disable "ACPI\PNP0501"
timeout /t 5
Devcon enable "ACPI\PNP0501"
"Runas" seems to always want to run something else instead of everything else in a batch file?
G'day Regejok, thank you very much that works perfectly. Yes i am aware of the security implications of an open text password in a batch file, and i am aware i could make the user a local administrator. However doing that would be a lot more difficult than this solution (GPO's manage local users and they are kept overseas) and i don't want to confuse the user(s) any more than i need to.
Add in the fact that the equipment attached to this one PC is flakey at the best of times has led me here.
I really like the fact that i can run additional commands within the same batch file by using the /c switch. I don't know much at all about scripting so this is a great help :)
It looks like the ampersands are used in a similar was as brackets are when writing/typing too: devcon do-this "blah"(and then do this)Devcon do-that "blah again"
I understand.
I am trying to create a bat file that will run cmd as administrator, then execute net command as shown below:
runas /user:administrator cmd "net localgroup administrators mjordan /add"
The goal is to add whoever the current user is as a local administrator.
So the first part works like a charm, and asks for the admin password. Upon entering the admin PW however, I do not see said test user under the local admin group. My best guess is I made a syntax error. But oddly enough no errors show up and command-line exits as if it executed.
Also, how would I make this execute and add the current user to the local admin group (thinking in a %username% way)? Not sure I am using the proper terminology, but say the user logged on running this command is JSmith. How could I make it add without using his name so it works on any account rather than just JSmith
Do you guys notice any errors? ...I am fairly new to creating bat files, and am learning as much as I can, so i know i must have messed up somewhere. Also, any references or study help is appreciated! Thank you!
Any ideas why bat files don't run in some cases?
I have written an interactive batch script (also run as an exe) works on THOUSANDS of systems, HOWEVER, a small subset of systems will NOT launch the script. They open a black box window and then close the script without giving the user the bat menu. I tried the bat file association registry reset which ensures that .bat file association is correct but that didn't help.
What I have tried: bat registry fix (.reg file)
(which didn't seem to help, the script starts but doesn't run)
(I also tested a VERY basic script that printed Hello world which also didn't work)
Thanks everyone for your help. What I found out was:
(1) Reset the command prompt:
http://social.technet.microsoft.com/Forums/windows/en-US/0a74090e-53ce-4642-8dad-0523bfd6c8a2/cant-run-bat-batch-files?forum=w7itproui
(which did not work for me)
(2) In a command prompt I had the users type 'set path' which showed that they were missing /windows/system32/ for one user. So far I had one user put it in and it fixed it. One other user had %systemroot%/system32 which I will have them try adding the path the other way to see if it fixes it. Next I will see if I can just add that to the script.
I'm trying to download some files using a batch file, however after reading the username line an error is thrown 'Invalid command'.
In my batch file I call my ftp file as follows:
ftp -n -s:ftp_download.txt
my ftp_download.txt looks like this:
open myname.com
test#myname.com
test
lcd C:\myDownloads
cd download_files
get MY_NEW_FILES_*.xml
bye
However after the test#myname.com line an error is thrown 'Invalid command' and thus the script does not connect to my ftp server.
When authenticating as follows:
open myname.com
user test#myname.com test
I get the 'not connected' error
However using this username (test#myname.com) and password (test) I'm still able to connect using Filezilla .
Am I missing a command somewhere?
To those, like CharlesKSQL, who might stumble upon my question.
Here's how I got it to work (it turned out I had to use sftp for some reason so make sure it's enabled on your server);
The script (ftp_download.txt) contains the following:
option batch abort
option confirm off
open sftp://<username>:<password>#<host> -hostkey="<fingerprint/key>"
option transfer binary
cd <your folder>
get <some file>
If you do not know the fingerprint and/or key; you can find these in FileZilla when connecting trough sftp. They are shown in the popup that show up when you connect to your server for the first time or you could click the little lock-icon in the statusbar on the bottom right when you are connected already.
Now to actually connect you'll need a little bit of software (when using Windows) to create the secure connection. I used WinSCP.
You can download the portable executables here and place them (for easy usage) in the same folder as your batch file.
Then you can call the executable in your batch file by adding a parameter:
winscp.exe /script=ftp_download.txt
which should then execute your download script.
P.S.: it's been a while since I finished this, it's still working as far as I know.
Your text file should look like this:
open myname.com
user
<enter username here> <password here>
lcd C:\myDownloads
cd download_files
get MY_NEW_FILES_*.xml
bye
Try that and see if it helps
I have implemented automation through batch file to login into a remote server and run a series of commands therin. My batch file contents are as follows:
#ECHO OFF
ECHO 1 -^> Connect 2 Server
ECHO 2 -^> Quit
SET /p ID=Enter Choice :
IF "%ID%"=="1" start "" C:\work\putty.exe -load SessionName -l UserName -pw Password -m cmd.txt
IF "%ID%"=="2" exit
My cmd.txt file contains the following commands:
su superuser
password
ssh server
password
su MyID
password
The batch successfully connects to the server; but it fails to retain the session. Any tweak would be appreciated.
For my own use I verified what -m switch does for putty
The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
Roughly what I guessed. I think what's happening is that your commands might be running ok, but it terminates the session when done (which is also default behaviour for ssh [command] on unix. To get around this you could try running 'bash' at the end to start a terminal as that user, which should stay running until you exit. If this doesn't work you could try running 'sleep 10' to see if the session stays running longer - should verify that's the problem we're dealing with.
Much as stackoverflow demands strictly the answer to the question, which I hope I've provided above. I feel in this case it would be remiss to not flag the serious security concerns I'd have on what you're doing. I would maintain that you shouldn't answer a question about doing something securely (with ssh and root passwords involved) without covering potential security pitfalls.
What you're doing seems like a bad idea because:
it makes a file with two unencrypted root-capable passwords to anyone who finds that file
this script is also giving you root access by default, which isn't a safe way to operate. Ever accidentally type rm -r in the wrong window?
Also, someone messing with your second hop (by say, replacing the ssh server with a script to run ssh but log passwords) would get the password to the third hop with root privileges.
SSH keys should do away with using passwords to log on. Use them.
SSH port forwarding lets you also skip sshing from the second hop - instead just tunnel through it (I'm guessing the third box isn't internet accessible), again using ssh keys lets you skip passwords.
the first 'su superuser' shouldn't be necessary unless your permissions don't allow you ssh (does an ssh_allow group exist on that box?), which might be the problem you should actually fix - not being a member of the group allowed to use SSH.