How to transfer a file using sftp on UNIX

I want to transfer the .png file from a directory on my computer to a directory on a remote server.

I need to use SFTP to protect the file and transfer mode. And I already have a UNIX script file (.ksh) for copying files normally. How to implement SFTP transmission?

+5
source share
2 answers

Use sftpinstead of any command you use in your .ksh script. See sftp man for help.

You can also see scpsecure copy - scp man .

EDIT

sftp mainly for interactive operations, you need to specify the host with which you want to connect:

sftp example.com

, .

, scp :

scp /path/to/localfile user@host:/path/to/dest

.

2

scp sftp ssh , . this this

- . . this this. . , ,

scp -i private-key-file /path/to/local/file user@host:/path/to/remote

sftp -oIdentityFile=private-key-file -b batch-file user@host

, expect. script :

#!/usr/bin/expect
spawn sftp -b batch-file user@host
expect "*?assword:*"
send "pasword\n"
interact

. this, this this .

+10

sftp :

my_batch_file:

cd /root
get blah.txt
bye

, :

eric@dev /home/el $ sftp root@10.30.25.15 < my_batch_file
Connecting to 10.30.25.15...
Password:
sftp> cd /root
sftp> get blah.txt
Fetching /root/blah.txt to blah.txt
sftp> bye

blah.txt .

, :

sftp Bash script?

, , Bash :

#!/bin/bash
expect -c "
spawn sftp username@your_host
expect \"Password\"
send \"your_password_here\r\"
interact "

, "" "p", , . , , . .

+1

All Articles