Trouble automating winscp.com with Public Key

Advertisement

Mike250
Joined:
Posts:
3
Location:
Sydney, Australia

Trouble automating winscp.com with Public Key

Hi there,

I am connecting to a client SFTP via shared Public Key (*.ppk) which I am successfully performing via the current WinScp.exe and Winscp.com. I have verified connectivity by putting and getting files both in the GUI and command line.

What I can't seem to do is automate the put of files from the command line. If I perform the following steps, one by one, at the command line, I am successful:
cd \program files (x86)\winscp\
winscp.com /command "open myuser@files.myclient.net" /privatekey=C:\Export\Scripts\20130620.ppk
put C:\Export\Archive\*.zip upload/ 
close
exit    


So, I created a batch file to perform this task, which connects and authenticates to the SFTP site just fine, but it does not perform the put. I have the winscp> prompt but nothing after that. See the connection log below.

Searching for host...
Connecting to host...
Authenticating...
Using username "myuser".
Authenticating with public key "20130620". 
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] myuser@files.myclient.net
winscp>    

It just sits there. If I now manually enter put C:\Export\NoniB\Archive\*.zip upload/ the file will upload. I can't seem to get it to perform automatically. Any thoughts? Thank you in advance.

Reply with quote

Advertisement

Mike250
Joined:
Posts:
3
Location:
Sydney, Australia

Additionally

Let me add, I have also tried this approach.

sftp.bat
cd \program files (x86)\winscp\
winscp.com scp://myuser@files.myclient.net /privatekey=C:\Export\Scripts\20130620.ppk /script=c:\export\scripts\sftp.txt    

sftp.txt
option batch abort
option confirm off
put C:\Export\Archive\*.zip upload/ 
exit    

Same problem. Connects, authenticates, Active session - but no put. Awaiting at the prompt winscp>.

Searching for host... 
Connecting to host... 
Authenticating... 
Using username "myuser". 
Authenticating with public key "20130620". 
Authenticated. 
Starting the session... 
Reading remote directory... 
Session started. 
Active session: [1] myuser@files.myclient.net 
winscp>    


A bit baffled here, and have been digging through FAQ. I thank you kindly for any assistance.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Additionally

Your second approach was close. Though you should see following message as a very first line of an output (providing you are using a recent version of WinSCP):
Automatic actions are disabled when URL address is provided on command-line.

You should do this:

cd \program files (x86)\winscp\
winscp.com /script=c:\export\scripts\sftp.txt /log=c:\export\scripts\sftp.log    

sftp.txt:
option batch abort
option confirm off
open scp://myuser@files.myclient.net -privatekey=C:\Export\Scripts\20130620.ppk
put C:\Export\Archive\*.zip upload/
exit    

See here for details:
https://winscp.net/eng/docs/guide_automation

Note that I've added a /log=. If you still cannot make this work, please attach the log (c:\export\scripts\sftp.log).

Reply with quote

BalajiKK
Guest

Re: Additionally

Hi

I am new to WinSCP/SFTP and I am struggling to automate the file transfer. The issue I have is that on top of Public Key (*.ppk), I have passphrase to use to establish the connection. Can someone please advise where to put the passphrase in these codes?

sftp.bat:
cd \program files (x86)\winscp\
winscp.com /script=c:\export\scripts\sftp.txt /log=c:\export\scripts\sftp.log    

sftp.txt:
option batch abort
option confirm off
open scp://myuser@files.myclient.net -privatekey=C:\Export\Scripts\20130620.ppk
put C:\Export\Archive\*.csv
exit    

Thanks
Balaji


martin wrote:

Your second approach was close. Though you should see following message as a very first line of an output (providing you are using a recent version of WinSCP):
Automatic actions are disabled when URL address is provided on command-line.

You should do this:

cd \program files (x86)\winscp\
winscp.com /script=c:\export\scripts\sftp.txt /log=c:\export\scripts\sftp.log    

sftp.txt:
option batch abort
option confirm off
open scp://myuser@files.myclient.net -privatekey=C:\Export\Scripts\20130620.ppk
put C:\Export\Archive\*.zip upload/
exit    

See here for details:
https://winscp.net/eng/docs/guide_automation

Note that I've added a /log=. If you still cannot make this work, please attach the log (c:\export\scripts\sftp.log).

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Additionally

BalajiKK wrote:

I am new to WinSCP/SFTP and I am struggling to automate the file transfer. The issue I have is that on top of Public Key (*.ppk), I have passphrase to use to establish the connection. Can someone please advise where to put the passphrase in these codes?
There's -passphrase= switch:
https://winscp.net/eng/docs/scriptcommand_open#passphrase

See also https://winscp.net/eng/docs/faq_passphrase#automating

Reply with quote

Advertisement

You can post new topics in this forum