putty psftp " and ; in password - vbscript

I am trying to create a vbscript to connect to a FTP server using putty. The problem I am having is the password has a ; and " in it. I have tried putting the password in " and also using \ to escape the charters
e.g.
-pw 3this;IsMyPwd" is what i want to use
Tried
"3this;IsMyPwd""" -> putty does not connect to remote server
-pw 3this;IsMyPwd""" -> putty does not connect to remote server
3this\;IsMyPwd\" -> putty does not connect to remote server
3this;IsMyPwd\" -> putty does connect to remote server but asks for a password or just hangs
-pw 3this;IsMyPwd"" > putty does connect to remote server but asks for a password or just hangs

The answer is to not use putty. I used WinSCP. You do not have to install it on the server you can copy WinSCP.com and WinSCP.exe to a folder.
Create a file with the commands, note that %22 url encoding of "
example of Cmd.txt file
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect
open sftp://USERNAME:password%3%22#ftp.server.org
ls
cd to_folder
ls
close
exit
Run the command C:\winScp> winscp.com /script=Cmd.txt

Related

SSH to remote Windows machine using username and password through shell script

I am trying to SSH to a remote Windows machine (an AWS ec2 instance) by using an username and password of the remote machine. I need to automate this connection to run some remote commands from my script (either shell or Power shell) without prompting me for a password, My script shouldn't fail by expecting a password to be prompted
I don't want to use sshpass or any generated keys (by using ssh-keygen). Since the source machine where I run this command/script is not a dedicated machine, I may run it on a different machine everytime. I also gave a try to connect using the .PEM file provided by AWS as below (thought it could be easy while using it the script).
$ssh -i aws_keypair.pem Administrator#10.10.10.10
Administrator#10.10.10.10's password:
It is still expecting me for a password even if I used the .PEM file, I also tried to created an file 'authorized_keys' in the remote Windows machine under the path "C:\Users\Administrator.ssh\". Still it is prompting me for a password.
Expectation :
Connect to remote Windows machine using PEM file and run some remote commands.
(or)
It shouldn't prompt me for a password while I try for the connection from some script (shell/power shell).
Can be done without any 3rd party tools like this:
$env:TMPPW=Get-Content -Path 'secure_file.txt' ; $un='MyUserName'
$j=Start-Job -ScriptBlock{Start-Sleep -Seconds 1
(New-Object -ComObject wscript.shell).SendKeys("$env:TMPPW{ENTER}")}
& ssh.exe -q -4 -l $un 127.0.0.1 'whoami'
$env:TMPPW=([guid]::NewGuid()).Guid ; $env:TMPPW=$null
I am able to achieve this using Plink command (Installation of Putty is required on source machine to execute this command). So now, I am able to successfully pass the username and password with in the script (Shell script) and everything is working as expected.
FYI, I am pasting the exact command which worked for me
$echo y | plink -ssh Administrator#10.10.10.10 -pw abc123 "dir"

Shell Script to access a remote machine using ssh with usr and pwd both

I am writing a shell script that can connect to another remote machine and query the DB , write the result in a file and copy the file back to main machine.
I am facing issue while connecting to DB.
I am not understanding how to connect to the remote machine.
I am using ssh root#DB_IP the then ORACLE query. But its always asking a password.
How to provide both username and password while doing a ssh to the remote machine?
You can do this by two ways:-
By adding your id.rsa.pub in your remote machine (~/.ssh/authorized_keys)
sshpass -p password ssh root#ip "sh run.sh "

sftp from batch file

I need some files from unix server. So, I am making sftp connection with password from my windows 7 machine to unix server. but, now i want to include all these commands in batch file.
So, I need help on how should make sftp connection from batch file (basically, how to pass password to sftp prompt from batch file)?
Commands I am using:
> C:\Users\e578589>sftp
> server : TSEDCLVSAPPD116.svr.us.jpmchase.net
> user name : a_avatar
>a_avatar's Password:
/home/a_avatar>cd /data/ailsa/archive/open-loans-txns-to-bancs
/dev2/data/ailsa/archive/open-loans-txns-to-bancs> get {$FILENAME}
May be the following solution you can think for your unix/linus server as well.
Secure FTP using Windows batch script
How about PSCP - PuTTY Download Page? It is easy to use in batch script.
pscp.exe -P PORT -pw PASSWORD USERNAME#IPADDRESS:SOURCE_PATH DEST_PATH
Perhaps you can use PSFTP (PuTTY Download Page) in the same way.

How to convert Windows FTP script to WinSCP?

I need to use WinSCP in my legacy vb6 code. I always used my script like this:
open ftp.myserver.com
myusername
mypassword
passive on
cd myfolder\
ascii
put C:\temp\test.xml test.xml
close
quit
Similar script (with little change) always worked for sslftp, psftp, etc.
Now I need to create script to make this WinSCP work but it keeps throwing "host not found error". I'm not even trying the script. I'm trying it on the command window.
winscp> open ftp.myserver.com
Searching for host...
Network error: Connection timed out.
same ftp works on regular command line ftp:
ftp> open ftp.myserver.com
Connected to myserver.
220 Gene6 FTP Server v3.10.0
User (...): myuser
331 Password required for myuser
Password:
230 User manager logged in.
How do I run WinSCP? The documentation doesn't show any such example.
WinSCP defaults to the SFTP protocol on the port 22. If you want to use the FTP, you need to specify that explicitly.
Also username and password come in session URL as part of the open command, not on separate lines. The passive mode is specified using the -passive=on switch.
open ftp://myusername:mypassword#ftp.myserver.com -passive=on
The ascii mode is specified using the -transfer=ascii switch of the put command (though the separate ascii command is also understood for compatibility):
put -transfer=ascii C:\temp\test.xml test.xml
It's the exit, not the quit.
See the complete guide for converting Windows FTP script to WinSCP.
You should also read the guide to automating file transfers to FTP server.

bash script to sftp files with a password from remote directories to local folders

How to write a bash script using sftp command to download files?
I can use the following command to login to the remote machine, however I need to type in the password manually.
bash-3.2$ sftp -o "Port 22022" mike#s-edm-ssh.local.files.stack.com
mike#s-edm-ssh.local.files.stack.com's password:
Connected to s-edm-ssh.local.files.stack.com.
sftp>
How to do the sftp without the password prompt?
If I like to download aaa.txt file at /remote/mike/files to my local directory /local/mike/downloaded, how to build a script to do all of these work?
Since sftp runs over SSH, you can place your public key on the remote server.
If for some reason you can't place your key on the server, then you can write an Expect script to send your password when the prompt appears. See this example.

Resources