|
|
#1 |
|
Prospect
Join Date: Jun 2010
Posts: 14
|
Scripting SFTP [non-interactive]
Hi All,
I'm trying to automate a file upload via sftp. My though was to write a simple shell script and run that script via launchd. Looking at the man page for sftp it appears that the sftp command only works in interactive mode. which would confirm why my script is not working: Code:
#!/bin/bash # Uploads a specified file to a remote server via sftp # Sets the remote Server SERVER="user@sftp.server.com.au" # Sets the local file to upload FILE="/path/to/file" # Upload the file to the server SFTP $SERVER put $FILE quit exit 0 The sftp server I'm trying to connect to is a Windows box running WinSSHD http://www.bitvise.com/winsshd. I tried doing a scp copy via ssh but the terminal session doesn't start—I'm presuming an incompatibility with the window command line I've setup private/public keys on the server and user account so no password is required. Any suggestions on automating a file copy via ssh or sftp to a windows server? I'm thinking of just using Panic's Transmit disk feature and doing a copy that way. Thanks in advance. |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
|
Perhaps using the 'expect' command will help.
('expect' is designed for scripting interactive command-line programs) Read 'man expect'
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
Why don't you use scp?
Code:
#!/bin/bash # Uploads a specified file to a remote server via sftp # Sets the remote Server SERVER="user@sftp.server.com.au" # Sets the local file to upload FILE="/path/to/file" # Upload the file to the server scp $FILE $SERVER exit 0 Another option is to use the batch mode of sftp: Code:
(echo put $FILE; echo quit) | sftp -b - $SERVER exit 0 Last edited by SirDice; 07-07-2011 at 12:27 AM. |
|
|
|
|
|
#4 |
|
Prospect
Join Date: Jun 2010
Posts: 14
|
That worked a treat, Thanks SirDice
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|