Tuesday, February 7, 2012

SFTP commands


List of SFTP commands (SFTP will abort if any of the following commands fail):

get [flags] remote-path[local-path]
Retrieve the remote-path and store it on the local machine. If the local path name is not specified, it is given the same name it has on the remote machine.
put [flags] local-path [local-path]
Upload local-path and store it on the remote machine. If the remote path name is not specified, it is given the same name it has on the local machine.
rename oldpath newpath
Rename remote file from oldpath to newpath.
ln oldpath newpath
Create a symbolic link from oldpath to newpath.
rm path
Delete remote file specified by path.
lmkdir path
Create local directory specified by path.
bye
Quit sftp.
exit
Quit sftp.
quit
Quit sftp.
cd path
Change remote directory to path.
lcd path
Change local directory to path.
ls [path]
Display remote directory listing of either path or current directory if path is not specified.
pwd
Display remote working directory.
rmdir path
Remove remote directory specified by path.
chgrp grp path
Change group of file path to grp. grp must be a numeric GID.
chmod mode path
Change permissions of file path to mode.
chown own path
Change owner of file path to own. own must be a numeric UID.
symlink oldpath newpath
Create a symbolic link from oldpath to newpath.
mkdir path
Create remote directory specified by path.
lls [ls-options [path]]
Display local directory listing of either path or current directory if path is not specified.
lpwd
Print local working directory.
lumask umask
Set local umask to umask.
! command
Execute command in local shell.
!
Escape to local shell.
?
Synonym for help.
help
Display help text


Example:   here I’m transferring ‘.dmp’ files from prod to test server using ‘SFTP’.

From test server:
/var/backup/ $  sftp  chandra@prodhostname
chandra@prodhostname's password: ********
Connected to prodhostname.

sftp> cd /var/backup/corpdb/datapump/                   (moving to datapump location on prod)
sftp> bye                                                                            (quits from sftp prompt)

(creating directories  corpdb and datapump on local server(test))

/var/backup/ $  mkdir corpdb                             
/var/backup/ $ cd corpdb
/var/backup/corpdb/  $  mkdir datapump
/var/backup/corpdb/ $   cd datapump
/var/backup/corpdb/datapump/ $  sftp chandra@prodhostname
chandra@host2's password: ********               (connecting to prod server using prod username)
Connected to host2.

sftp> cd /var/backup                          (moving to datapump location on prod(remote server))
sftp> ls                                              (lists all files & folders in /var/backup location on remote server(prod))
sftp> cd  /var/backup/corpdb
sftp> cd  /var/backup/corpdb/datapump  
sftp> get *.dmp                                    (getting .dmp files from prod to test server)

Fetching /var/backup/corpdb/datapump/CORP01.dmp to CORP01.dmp
/var/backup/corpdb/datapump/CORP01.dmp        0%  192MB  1MB/s   992.0KB/s  5:58:45 ETA


Where          0%             -      Percentage of the file that has been transferred at this point
                    192MB       -     Amount of Data Transferred
                    1Mbps        -     Transfer rate
                    ETA            -     Estimated Time of Arrival(i.e. Remaining Time)

NOTE :   We can also give sftp>  get *.dmp /var/backup/corpdb/datapump   but since we are connected from /var/backup/corpdb/datapump   location so no need of specifying path, by default it will place all the files in the location from where you are connected to SFTP.

Similarly the same operation can be done through prod server also but the only difference is use 'PUT' command in place of 'GET' command.
                                                
Hope this helps, ALL THE BEST




0 comments:

Post a Comment

Auto Scroll Stop Scroll