Unix_linux Ftp Cmds
Click here to load reader
-
Upload
swaroop-vanteru -
Category
Documents
-
view
4 -
download
0
description
Transcript of Unix_linux Ftp Cmds
Linux / UNIX FTP Commands Tutorialby NIXCRAFT on AUGUST 8, 2010 · 3 COMMENTS · LAST UPDATED AUGUST 8, 2010
in UNIX
Iswitched from MS-Windows to Mac computer running OS X
UNIX systems. I need to transfer and download file using ftp for my personal website. Can you provide me a list of FTP commands that may be sent to an FTP server, to upload and download files using UNIX / Linux ftp command line client?
File Transfer Protocol (FTP) is a network protocol used to copy a file from one computer to another over the Internet or LAN. FTP follows a client-server architecture which utilizes separate control and data connections between the ftp client and server. The default port for ftp is 21.
WARNING! These examples uses outdated insecure ftp protocol / client and if executed you are open to various attacks including password snooping. I strongly recommend that you use sftp, the secure version of FTP. Just type sftp instead of ftp and all of the following commands should work with sftp client too.
ftp: Internet File Transfer ProgramUse the following syntax to connect to transfer files to and from a remote network ftp site:
ftp ftp.example.com
ftp 1.2.3.4
You must know ftp username and password for user-based password authentication or with anonymous user access use ftp as both username and password. In this example, you are connecting to ftp.freebsd.org with anonymous user access (open the terminal and type the following command):$ ftp ftp.freebsd.orgSample session:Trying 87.51.34.132...
Connected to ftp.freebsd.org.
220 ftp.beastie.tdk.net FTP server (Version 6.00LS) ready.
Name (ftp.freebsd.org:vivek): ftp331 Guest login ok, send your email address as password.Password:230 Guest login ok, access restrictions apply.Remote system type is UNIX.Using binary mode to transfer files.ftp>
When you enter your own loginname and password for the ftp.example.com server, it returns the prompt
ftp>
You need to type all commands in front of the ftp> prompt.
Task: List Current FileType the ls command at ftp> prompt:ftp> lsSample outputs:229 Entering Extended Passive Mode (|||60692|)
150 Opening ASCII mode data connection for '/bin/ls'.
total 10
drwxrwxr-x 2 0 5 512 Jul 19 2007 .snap
drwx------ 2 0 0 2048 Jul 19 2007 lost+found
drwxr-xr-x 3 1006 1006 512 Sep 21 2009 pub
drwxr-xr-x 3 1006 1006 512 Jun 5 2007 sup
drwxr-xr-x 4 1006 0 512 Sep 18 2009 www
226 Transfer complete.
ftp>
The above will list the names of the files in the current remote directory (the last name is file or dir name).
Task: Change DirectoryTo change directory on the remote machine use cd command:ftp> cd dirNameTo change to pub directory, enter:ftp> cd pubSample outputs:250 CWD command successful.
Task: Download / Copy fileTo copy one file at a time from the remote ftp server to the local system use get command:
get fileName
get fileName newFileName
In this example, download file resume.pdf in the current remote directory to (or on top of) a file with the same name, resume.pdf, in your current local directory:ftp> get resume.pdfSample outputs:local: resume.pdf remote: resume.pdf
229 Entering Extended Passive Mode (|||55093|)
150 Opening BINARY mode data connection for 'resume.pdf' (53077 bytes).
100% |*********************************************************************| 53077 12.58 KiB/s 00:00 ETA
226 Transfer complete.
53077 bytes received in 00:04 (12.57 KiB/s)
In this example, copies file data.tar.gz in the current remote directory to (or on top of) a file named backup.tar.gz in your current local directory:ftp> get data.tar.gz backup.tar.gzChange Local DirectoryTo change directory on your local system, enter:ftp> lcd /path/to/new/dirftp> lcd /tmpSample outputs:Local directory now: /tmp
Print local directory:ftp> lpwdSample outputs:/tmp
The lpwd command prints current download directory for local systems. However, to find out the pathname of the current
directory on the remote ftp server, enter:ftp> pwdSample outputs:Remote directory: /pub/FreeBSD
Task: Download Multiple FilesYou need to use mget command as follows to copy multiple files from the remote ftp server to the local system. You may be prompted for a yes/no (Y/N) answer before transferring each file (you can disable prompt by passing the -i option to ftp client). To download all files, enter:ftp> mget *To download all perl files (ending with .pl extension), enter:ftp> mget *.pl
Task: Turn On / Off Interactive PromptingThe ftp command prompt sets interactive prompting; "on" which enables prompting so that you can verify of each step of the multiple commands, "off" allows the commands to act unimpeded:ftp> prompt onftp> mput *.phpftp> prompt off ftp> mget *.py
Task: Delete FileTo delete a file in the current remote directory use delete command:ftp> delete fileNameftp> delete output.jpg
Task: Upload One FileTo copy one file at a time from the local systems to the remote ftp server, enter:ftp> put fileNameIn this example, upload logo.jpg, enter:ftp> put logo.jpg
Task: Upload Multiple FilesTo copy multiple files from the local system to the remote ftp server use mput command. Again, you may be prompted for a yes/no (y/n) answer before transferring each file. In this example, upload all files from the current system:ftp> mput *ftp> mput *.pl
Task: Create a DirectoryTo make a new directory, enter:ftp> mkdir dirNameftp> mkdir scriptsftp> cd scriptsftp> pwd
Task: Delete a DirectoryTo remove or delete a directory, enter:ftp> rmdir dirNameftp> rmdir imagesftp> ls
Task: Set The Mode Of File Transfer
To set the mode of file transfer to ASCII, enter:ftp> asciiPlease note that ascii is the default and good for text files. To set the mode of file transfer to binary, enter:ftp> binaryThe binary mode is recommended for almost all sort of files including images, zip files and much more. The binary mode provides less chance of a transmission error.
Task: Connect To Another FTP ServerTo open a connection with another ftp server, enter:ftp> open ftp.nixcraft.net.inThe above command opens a new FTP connection with ftp.nixcraft.net.in. You must provide a username and password for a ftp.nixcraft.net.in account. However, a username and password can be skipped for an anonymous FTP connection.
Task: Exit the FTP SessionType quit or bye, enter:ftp> quitORftp> byeSample outputs:221 Goodbye.
How Do I Find Out More Information About The FTP Commands?
Type ? or help to get more information about the FTP commands:ftp> ?ftp> helpSample outputs:Commands may be abbreviated. Commands are:
! delete idle mode pmlsdreset system
$ dir image modtimepreserve restart tenex
account disconnect lcd moreprogress rhelp throttle
append edit less mput promptrmdir trace
ascii epsv4 lpage mreget proxyrstatus type
bell exit lpwd msend putrunique umask
binary features ls newer pwdsend unset
bye fget macdef nlist quitsendport usage
case form mdelete nmap quoteset user
cd ftp mdir ntrans ratesite verbose
cdup gate mget open rcvbufsize xferbuf
chmod get mkdir page recvsndbuf ?
close glob mls passive regetstatus
cr hash mlsd pdir remoptsstruct
debug help mlst pls renamesunique
To get a short description about each command, enter:ftp> help commandNameftp> help chmodSample outputs:chmod change file permissions of remote file
ftp> help lsSample outputs:
ls list contents of remote path
FTP Through A BrowserIf you do not want to type the commands, than use a browser such as Safari, Firefox and type the following:ftp://[email protected]://ftp.freebsd.org/ftp://[email protected]/ftp://userName:[email protected]/ftp://ftp:[email protected]/