Most MFT solutions use a file system approach, and require folder permissions and custom scripts for each workflow. DataMotion Secure File Transfer Automation uses a simpler, results-oriented approach to easily describe and manage your transfers without the need for scripts, file. Reduce Complexity of Tedious File Transfer Tasks. Automation allows you to deliver data without manual intervention, saving time and avoiding potential errors. Enhanced File Transfer™ (EFT™) Enterprise and Express enables you to streamline business processes without limitations imposed by legacy systems and applications.
I have a batch file for moving file from my local PC to server through SFTP. I have PuTTY installed in my system and the batch file code follows.
The above code perfectly works when I type it in command prompt. But when I double click the
.bat
file and run it, it's not running and asking for username and password to be entered. My aim was to automate the whole thing and I need to run it by simply clicking the .bat
file. But am not able to achieve it. Any ideas or snippets will help me.sureshsuresh
2 Answers
You need to store the psftp script (lines from
open
to bye
) into a separate file and pass that to psftp
using -b
switch:Where
script.txt
is assumed to be in C:Program Files (x86)PuTTY
. Alternatively provide a full path (Do not forget to enclose the path to double-quotes, particularly if it contain spaces. You should better do this with your cd
command too).Reference:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-option-b
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-option-b
EDIT: For username+password: As you cannot use
psftp
commands in a batch file, for the same reason, you cannot specify the username and the password as psftp
commands. These are inputs to the open
command. While you can specify the username with the open
command (open <user>@<IP>
), you cannot specify the password this way. This can be done on a psftp
command line only. Then it's probably cleaner to do all on the command-line: And remove the
open
, <user>
and <PW>
lines from your script.txt
.Reference:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-starting
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-pw
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-starting
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-pw
What you are doing atm is that you run
psftp
without any parameter or commands. Once you exit it (like by typing bye
), your batch file continues trying to run open
command (and others), what Windows shell obviously does not understand.If you really want to keep everything in one file (the batch file), you can write commands to psftp standard input, like:
Martin PrikrylMartin Prikryl
Set values using set commands before above lines.
I believe this helps you.
Referre psfpt setup for below link https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter6.html
Rajkumar SRajkumar S
Not the answer you're looking for? Browse other questions tagged batch-filecmdsftpputtypsftp or ask your own question.
SFTP server and client
Last week's README file demonstrated how easy it is to turn virtually any desktop machine into an SFTP server. Today's piece shows how to automate a well-known Windows open source SFTP client using script files.
WinSCP installation and settings
For this short tutorial I am using the WinSCP SFTP client for Windows. I installed WinSCP using the Custom Installation option, and at the Select Additional Tasks step, I made sure that Add installation directory to search path box was checked.
Checking this option helps to simplify WinSCP scripts and batch files -- this is because the full path of the WinSCP executable won't be needed in order to run the SFTP client from the command line.
Also, if possible, connect to the remote SFTP server first with the GUI application before connecting via the command line. Doing this allows you to easily add the remote server's host key to WinSCP's key cache.
Script creation
![File transfer automation File transfer automation](https://www.goanywhere.com/assets/img/blog-images/2019/01/850x330-10-ways.jpg)
I kick off SFTP scripts from the command line using a traditional batch file. For example, this is a listing of a batch file named deploy.bat -- used to start the SFTP client with script file. Notice the commented lines in the file, these lines are not needed if the option to add the WinSCP's folder to %PATH% was selected during installation.
Notice too, the script file is named uploadscript.txt, specified by the /script parameter.
Finally, we examine the script file itself. In this example, I am opening a connection to an SFTP server (192.168.1.17) on my local network, specifying username (glasskeys) with password (somepassword). I then change the local directory to C:temp, and instruct the SFTP client to copy a subfolder named 'asubfolder', lastly, I instruct the client to copy a single document named atestdoc.txt to the remote server before exit:
You may be curious about the nopermissions and nopreservetime switches. WinSCP's put command documentation tells us that nopermissions keeps default file permissions, and nopreservetime instructs the remote server to replace timestamp information. Based on past experience, I've found that using both of these switches helps to mitigate problems -- especially when overwriting files on remote SFTP servers.
This is a screenshot of the deploy batch file executing in a command window:
For more information, consult WinSCP's extensive scripting documentation here.
This article is published as part of the IDG Contributor Network. Want to Join?