Run sftp Batch Files
Using sftp batch files provides a secure way to automate file management.
To create and run an sftp batch file
- Configure the client and server to support a non-interactive client authentication method, such as GSSAPI, or public key without passphrase protection.
Note: Authentication methods that require interaction are not supported when you use the sftp batch file option (-B).
- On the client, create an sftp batch file. The batch file can use any of the interactive commands supported by sftp. For example, you might create a file called demo with commands such as:
- Use sftp to connect to the remote host and run the batch file. For example:
sftp -B demo firstname.lastname@example.org
The client runs the commands in the batch file and then exits.
- After a successful login, sftp executes each command in the batch file until a bye, exit or quit command is found, and then terminates the connection.
- If a command in the batch file fails, sftp continues executing the remaining commands, and returns the error code of the first failed command. However, commands prefixed with "-" (dash) always return 0, even if the command fails. To configure a batch file that returns a separate error for each transfer command, use scp.