lots of tech info here

File transfer using Linux or Unix

There are many file transfer methods for both Linux, Unix and Windows environments, but I am going to focus on the command line programs on the Linux and Unix platforms.

Windows users can use most of these if the command line programs are installed.

If you need to transfer files between your computer and a remote server foo.com this tutorial is for you.

Also check out my Shell Script to automate file transfer using FTP.

FTP (file transfer protocol)

This is mostly used to copy files between computers. It doesn't support compression. It is also not encrypted. To transfer files, run this at the terminal:

  ftp foo.com

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

If the file being transferred is a binary file (example PDF, PS, GIF, JPG, PNG 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 WinSCP program.

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 sftp from 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

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

Posted on 01 Jan 2005

TAGS: file, unix, linux

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others

Subscribe

Tags