sftp from batch file - windows

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.

Related

SFTP file from one remote server to other remote server using shell script without expect package

I'm trying to automate the transfer of files from one remote server to other remoter server using shell script. I cannot install expect package. Could anyone help me out in doing this?
Thanks.
Setup a password less login between remote server so it won't ask for password in shell script and it will avoid passing password in shell script for security reason
Please refer the below link to setup password less ssh
http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
Then write a shell script to sftp the files
refer the SFTP command in the below link to do the needful
http://www.tecmint.com/sftp-command-examples/

Shell Script program to download files from linux remote server

I am very new in shell scripting , i want to download some files from linux remote server ,so how can i proceed for that.That remote server is ssh based .
first of all, ftp service is better choice to get files from remote server.
If only sshd service is available, then you may use ssh based command sftp or scp.
However, using sftp or scp commands will invoke an interactive password prompt, which is a problem in shell script --> You have to ask for help to expect command. see Automate scp file transfer using a shell script .
Besides expect, you may also set up trust relationship between two servers, then you may use scp without password. See http://www.linuxproblem.org/art_9.html

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.

Trying to delete files via a scheduled task and VBScript

I asked a previous question about downloading file unattended on a server, using VBScript and Windows Task Scheduler. (See
Scripting SFTP unattended download )
That works great but now I also need to delete the files from the server I am calling:
Set sessionses = WScript.CreateObject("WScript.Shell")
sessionses.Run "C:\TCS\SFTP\delThem.bat", , True
PSFTP calling a batch file that runs this command:
psftp user#host:22 -batch -b script.txt -pw pa$$word
script.txt is as follows:
cd FromCeridian
del *.GEN
If I run this command from the command line, or double click the batch file containing the command, it works "interactively", but when running unattended and scheduled, it doesn't do this part. The server is SFTP, so I can't just use win ftp commands to do it.
Any ideas?
Check the security options of your task to verify the user identity has correct access privileges.

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