|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
Softpanorama Search
|
| News | SSH | Recommended Links | Private and Public key management | Reference | WinSCP |
| ssh-keygen man page | SSH Usage in Pipes | SCP | Tips | humor | Etc |
SFTP is normally used as an intractive application/protocol, but also can be put into a batch mode with the -b flag. This can be specified with a file or can be directed stdin from an external script.
The password can not be passed by either process.
sftp [-1Cv] [-b batchfile] [-F SSH_config] [-o SSH_option] [-s subsystem | sftp_server] [-S program] host
sftp [[user@]host[:file [file]]]
sftp [[user@]host[:dir[/]]]
But mostly SFTP is used as an interactive file transfer program.
With FTP one might try to copy up all their JPG files to their image directory like this:
ftp> cd /home/user/images/
ftp> bin
ftp> prompt
ftp> mput *.jpg
With SFTP it is much simpler..
sftp> cd /home/user/images/
sftp> put *.jpgtt>
List of SFTP commands (SFTP will abort if any of the following commands fail):
List of other commands:
SFTP may also use many features of SSH, such as public key authentication and compression. SFTP connects and logs into the specified host, then enters an interactive command mode. The second usage format will retrieve files automatically if a noninteractive authentication method is used; otherwise it will do so after successful interactive authentication. The last usage format allows the sftp client to start in a remote directory.
Here are the options used:
|
|||||||
Even though the Linux version of the sftp client doesn’t offer a direct way to resume an interrupted transfer, doing so is quite simple by using common shell tools, as long as you are able to login to the remote server through a console. Assuming that you are transferring data.zip from source_server to target_server and the transfer was interrupted, you can do the following:
- Connect to target_server using ssh, since you will be required to perform some operations there. Navigate to the directory containing the partially transferred file (also called data.zip)
- Check the sizes of the original and the partially transferred files. The easiest way to do that is by using the ls -al data.zip command. Let’s assume that data.txt is 8231129 bytes long, and only 2811110 bytes were transferred before the interruption
- Subtract the size of the partially transferred file from the original, to get the remaining size in bytes. In this case, it is 5420019 bytes. In case you didn’t know, Linux has a practical command-line calculator, bc, which comes very handy for quick calculations
- In source_server, create a new file consisting of the last 5420019 bytes of the original. You can do this with the tail command: tail -c 5420019 data.zip >data.tail
- Transfer the data.tail file to target_server, using sftp as usually.
- Once the transfer is complete, delete data.tail from source_server to avoid any mistake that would corrupt your original file.
- In target_server, use the cat command to append data.tail to the partially transferred file: cat data.tail >>data.zip (Note the double >>)
This works for both text and binary files. Apparently a better way would be integrating this ability into the sftp client, which is the way some clients such as putty and winscp work, but until that happy day you can use the tips above as a workaround.
Comments
mikeX:
lftp is a very nice command line ftp client, which supports tab completion, directory mirroring and of course resuming of interrupted downloads. It can also work as an sftp client, with the right protocol prefix, e.g. lftp sftp://user@host, and can even be used in batch mode. You can find a copy at http://lftp.yar.ru/. Still, nice trick :)
Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
Last modified: March 16, 2010