How to set up a PSFTP job to push files off a Windows box through schedule task in windows
1:51 PM
Windows has FTP built-in. But not SFTP. There are some good open source SFTP solutions available for windows and this article is for Putty SFTP.
Install putty sftp and run the psftp through command prompt. The arguments and options will be available with the command of below
D:\latheef_test>"C:\Program Files (x86)\Putty\psftp.exe" -h
PuTTY Secure File Transfer (SFTP) client
Release 0.62
Usage: psftp [options] [user@]host
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-b file use specified batchfile
-bc output batchfile commands
-be don't stop batchfile processing if errors
-v show verbose messages
-load sessname Load settings from saved session
-l user connect with specified username
-P port connect to specified port
-pw passw login with specified password
-1 -2 force use of particular SSH protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-batch disable all interactive prompts
Connecting PSFTP through command prompt.
psftp [user@host] -P [port] -pw [password]
Once you logged on to the PSFTP, type help to know more about the commands available.
If you would like to perform the upload, delete, quit etc., through script, Add the commands you wanted to execute once you logged on to the sftp and save that as text file.
Example
mv D:\test\testfile
rm log.txt
quit
Once the text file is ready with the commands, there is an option available in psftp to include the file.
psftp [user@host] -P [port] -pw [password] -b [path of the commands file]
Now when you run this from command prompt it will work fine, but when you configure the script from schedule task with run as different user it will not work.
Reason:
When you run the command manually through command prompt at the first time it will ask you to store the key in cache. So it will work if you configured the schedule task to run as the user who already added the key in the cache. But if you configured the schedule task to run as a different user, the command prompt will stuck in asking the permission to store the key in the cache.
Solution:
Logon to the user as you will be configuring that to run the schedule task and run the command manually through command prompt to add the key in the cache. Once you done that logoff and run the schedule task and it should work.
Install putty sftp and run the psftp through command prompt. The arguments and options will be available with the command of below
D:\latheef_test>"C:\Program Files (x86)\Putty\psftp.exe" -h
PuTTY Secure File Transfer (SFTP) client
Release 0.62
Usage: psftp [options] [user@]host
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-b file use specified batchfile
-bc output batchfile commands
-be don't stop batchfile processing if errors
-v show verbose messages
-load sessname Load settings from saved session
-l user connect with specified username
-P port connect to specified port
-pw passw login with specified password
-1 -2 force use of particular SSH protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-batch disable all interactive prompts
Connecting PSFTP through command prompt.
psftp [user@host] -P [port] -pw [password]
Once you logged on to the PSFTP, type help to know more about the commands available.
If you would like to perform the upload, delete, quit etc., through script, Add the commands you wanted to execute once you logged on to the sftp and save that as text file.
Example
mv D:\test\testfile
rm log.txt
quit
Once the text file is ready with the commands, there is an option available in psftp to include the file.
psftp [user@host] -P [port] -pw [password] -b [path of the commands file]
Now when you run this from command prompt it will work fine, but when you configure the script from schedule task with run as different user it will not work.
Reason:
When you run the command manually through command prompt at the first time it will ask you to store the key in cache. So it will work if you configured the schedule task to run as the user who already added the key in the cache. But if you configured the schedule task to run as a different user, the command prompt will stuck in asking the permission to store the key in the cache.
Solution:
Logon to the user as you will be configuring that to run the schedule task and run the command manually through command prompt to add the key in the cache. Once you done that logoff and run the schedule task and it should work.
0 comments