FTP (file transfer protocol)

This is mostly used to copy files between computers. It doesn’t support compression. It is also not encrypted. This is how to transfer files.

To connect to foo.com

ftp foo.com

You will have to enter your username and password when prompted.

If the file being transferred is a binary file (yes, PDF and PS are binary files), type the following.

binary

To upload your file wolf.pdf to the directory in foo.com

cd /home/arul/backup
put wolf.pdf

To download the file arul.ps from the directory in foo.com

get arul.ps

If you have multiple files, use mget instead of get and mput instead of put.

To quit, type bye. This is just the basic file transfer using FTP. To check all the options using FTP, type man ftp from your shell prompt.

SFTP (secure file transfer protocol)

SFTP is an interactive file transfer program, similar to FTP, which performs all operations over an encrypted secsh transport. If you are a Windows user, you will need a secure file transfer program like WinSCPprogram.

To connect to foo.com here is what you should do.

sftp foo.com

You will have to enter your username and password when prompted.

To upload your file wolf.pdf to the directory in foo.com

cd /home/arul/backup
put wolf.pdf

To download the file arul.ps from the directory in foo.com

get arul.ps

If you want to download multiple files, say all PDF files,

get *.pdf

To quit, type exit. This is just the basic SFTP. To check all the options using SFTP, type man sftpfrom your shell prompt.

SCP (secure copy)

SCP is used for single file transfers unlike SFTP or FTP, where once connected, you can carry out any number of transfers.

To upload the file wolf.pdf to the /home/arul/backup in the remote computer foo.com here is what you should do. Lets say the username and password for connecting to foo.com are us3r and p4ssword respectively, read ahead.

scp wolf.pdf us3r@foo.com:/home/arul/backup/

You will be prompted for your password, which you should enter. It uploads the file and quits automatically.. all in one operation.

To download the file arul.ps from the remote directory, here is what you must do.

scp us3r@foo.com:/home/arul/backup/arul.ps

If you want to upload the entire perl directory (recursively) here is what you do.

scp -r /home/wolf/perl us3r@foo.com:/home/arul/backup/

wget

To download the index.html page of gnome.org, here is what you type.

wget http://www.gnome.org/index.html

… and you have the index.html page on your current directory🙂

If you want to rip the website upto 3 levels,

wget -r -l 3 http://www.gnome.org

Shell Script to automate upload using FTP

I wrote this simple shell script to automate upload and download of files.. just customise it according to your use.

#!/bin/bash

HOST='foo.com'
USER='us3r'
PASSWD='p4ssword'

ftp -i -n $HOST <<Arul
user ${USER} ${PASSWD}

binary
cd /home/arul/backup
put wolf.pdf
get arul.ps

quit
Arul

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s