Sunday, November 30, 2008

List of FTP commands for the Microsoft command-line FTP client

List of FTP commands for the Microsoft command-line FTP client

Command-line options

As you're starting the program from a DOS prompt:
ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]

  • -v - Suppresses verbose display of remote server responses.
  • -n - Suppresses auto-login upon initial connection.
  • -i - Turns off interactive prompting during multiple file transfers.
  • -d - Enables debugging, displaying all ftp commands passed between the client and server.
  • -g - Disables filename globbing, which permits the use of wildcard chracters in local file and path names.
  • -s:filename - Specifies a text file containing ftp commands; the commands will automatically run after ftp starts. No spaces are allowed in this parameter. Use this switch instead of redirection (>).
  • -a - Use any local interface when binding data connection.
  • -w:windowsize - Overrides the default transfer buffer size of 4096.
  • computer - Specifies the computer name or IP address of the remote computer to connect to. The computer, if specified, must be the last parameter on the line.

Client commands

  • ! - Runs the specified command on the local computer
  • ? - Displays descriptions for ftp commands
  • append - Appends a local file to a file on the remote computer
  • ascii - Sets the file transfer type to ASCII, the default
  • bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)
  • binary - Sets the file transfer type to binary
  • bye - Ends the FTP session and exits ftp
  • cd - Changes the working directory on the remote computer
  • close - Ends the FTP session and returns to the command interpreter
  • debug - Toggles debugging (default = OFF)
  • delete - Deletes a single file on a remote computer
  • dir - Displays a list of a remote directory's files and subdirectories
  • disconnect - Disconnects from the remote computer, retaining the ftp prompt
  • get - Copies a single remote file to the local computer
  • glob - Toggles filename globbing (wildcard characters) (default = ON)
  • hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)
  • help - Displays descriptions for ftp commands
  • lcd - Changes the working directory on the local computer
  • literal - Sends arguments, verbatim, to the remote FTP server
  • ls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mdelete - Deletes one or more files on a remote computer
  • mdir - Displays a list of a remote directory's files and subdirectories
  • mget - Copies one or more remote files to the local computer
  • mkdir - Creates a remote directory
  • mls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mput - Copies one or more local files to the remote computer
  • open - Connects to the specified FTP server
  • prompt - Toggles prompting (default = ON)
  • put - Copies a single local file to the remote computer
  • pwd - Displays the current directory on the remote computer (literally, "print working directory")
  • quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")
  • quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")
  • recv - Copies a remote file to the local computer
  • remotehelp - Displays help for remote commands
  • rename - Renames remote files
  • rmdir - Deletes a remote directory
  • send - Copies a local file to the remote computer (same as "put")
  • status - Displays the current status of FTP connections
  • trace - Toggles packet tracing (default = OFF)
  • type - Sets or displays the file transfer type (default = ASCII)
  • user - Specifes a user to the remote computer
  • verbose - Toggles verbose mode (default = ON)

!

Runs the specified command on the local computer.

Syntax: [command]

Parameter(s):
command - Specifies the command to run on the local computer. If command is omitted, the local command prompt is displayed; type "exit" to return to ftp.

?

Displays descriptions for ftp commands. ? is identical to help.

Syntax: [command]

Parameter(s):
command - Specifies the name of the command about which you want a description. If command is not specified, ftp displays a list of all commands.

append

Appends a local file to a file on the remote computer using the current file type setting.

Syntax: append local-file [remote-file]

Parameter(s):
local-file - Specifies the local file to add. 
remote-file - Specifies the file on the remote computer to which local-file will be added. If remote-file is omitted, the local filename is used for the remote filename.

ascii

Sets the file transfer type to ASCII, the default.

Syntax: ascii

Note
FTP supports two file transfer types, ASCII and binary image. ASCII should be used when transferring text files. See also binary.

In ASCII mode, character conversions to and from the network standard character set are performed. For example, end-of-line characters are converted as necessary, based on the target operating system.

bell

Toggles a bell to ring after each file transfer command is completed. By default, the bell is off.

Syntax: bell

binary

Sets the file transfer type to binary.

Syntax: binary

Note
FTP supports two file transfer types, ASCII and binary image. Binary should be used when transferring executable files. In binary mode, the file is moved byte-by-byte. See alsoascii.

bye

Ends the FTP session with the remote computer and exits ftp.

Syntax: bye

cd

Changes the working directory on the remote computer.

Syntax: cd remote-directory

Parameter(s):
remote-directory - Specifies the directory on the remote computer to change to.

close

Ends the FTP session with the remote server and returns to the command interpreter.

Syntax: close

debug

Toggles debugging. When debugging is on, each command sent to the remote computer is printed, preceded by the string --->. By default, debugging is off.

Syntax: debug

delete

Deletes a single file on a remote computer. See also mdelete, which can delete multiple files.

Syntax: delete remote-file

Parameter(s):
remote-file - Specifies the file to delete.

dir

Displays a list of a remote directory's files and subdirectories. See also mdir, which can list multiple directories.

Syntax: dir [remote-directory] [local-file]

Parameter(s):
remote-directory - Specifies the directory for which you want to see a listing. If no directory is specified, the current working directory on the remote computer is used. 
local-file - Specifies a local file to store the listing. If not specified, output is displayed on the screen.

disconnect

Disconnects from the remote computer, retaining the ftp prompt.

Syntax: disconnect

get

Copies a remote file to the local computer using the current file transfer type. See also mget, which can copy multiple files.

Syntax: get remote-file [local-file]

Parameter(s):
remote-file
Specifies the remote file to copy.

local-file
Specifies the name to use on the local computer. If not specified, the file is given the remote-file name.

glob

Toggles filename globbing. Globbing permits use of wildcard characters in local file or path names. By default, globbing is on.

Syntax: glob

hash

Toggles hash-sign (#) printing for each data block transferred. The size of a data block is 2048 bytes. By default, hash mark printing is off.

Syntax: hash

help

Displays descriptions for ftp commands.

Syntax: help [command]

Parameter(s):
command - Specifies the name of the command about which you want a description. If command is not specified, ftp displays a list of all commands.

lcd

Changes the working directory on the local computer. By default, the working directory is the directory in which ftp was started.

Syntax: lcd [directory]

Parameter(s):
directory - Specifies the directory on the local computer to change to. If directory is not specified, the current working directory on the local computer is displayed.

literal

Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return.

Syntax: literal argument [ ...]

Parameter(s):
argument - Specifies the argument to send to the FTP server.

ls

Displays an abbreviated list of a remote directory's files and subdirectories.

Syntax: ls [remote-directory] [local-file]

Parameter(s):
remote-directory - Specifies the directory for which you want to see a listing. If no directory is specified, the current working directory on the remote computer is used. 
local-file - Specifies a local file to store the listing. If not specified, output is displayed on the screen.

mdelete

Deletes one or more files on a remote computer.

Syntax: mdelete remote-files [ ...]

Parameter(s):
remote-files - Specifies the remote files to delete.

mdir

Displays a list of a remote directory's files and subdirectories. Mdir allows you to specify multiple files.

Syntax: mdir remote-files [ ...] local-file

Parameter(s):
remote-files - Specifies the directory for which you want to see a listing. Remote-files must be specified; type "-" to use the current working directory on the remote computer. 
local-file - Specifies a local file to store the listing. Type "-" to display the listing on the screen.

mget

Copies one or more remote files to the local computer using the current file transfer type.

Syntax: mget remote-files [ ...]

Parameter(s):
remote-files - Specifies the remote file(s) to copy to the local computer.

mkdir

Creates a remote directory.

Syntax: mkdir directory

Parameter(s):
directory - Specifies the name of the new remote directory.

mls

Displays an abbreviated list of a remote directory's files and subdirectories.

Syntax: mls remote-files [ ...] local-file

Parameter(s):
remote-files - Specifies the files for which you want to see a listing. Remote-files must be specified; type "-" to use the current working directory on the remote computer. 
local-file - Specifies a local file to store the listing. Type "-" to display the listing on the screen.

mput

Copies one or more local files to the remote computer using the current file transfer type.

Syntax: mput local-files [ ...]

Parameter(s):
local-files - Specifies the local files to copy to the remote computer.

open

Connects to the specified FTP server.

Syntax: open computer [port]

Parameter(s):
computer - Specifies the remote computer to connect to. Computer can be specified by IP address or computer name (a DNS or HOSTS file must be available). If auto-login is on (default), FTP also attempts to automatically log the user in to the FTP server (see Ftp command-line options to disable auto-login). 
port - Specifies a port number to use to contact an FTP server.

prompt

Toggles prompting. Ftp prompts during multiple file transfers to allow you to selectively retrieve or store files; mget and mput transfer all files if prompting is turned off. By default, prompting is on.

Syntax: prompt

put

Copies a local file to the remote computer using the current file transfer type. See also mput, which can copy multiple files.

Syntax: put local-file [remote-file]

Parameter(s):
local-file - Specifies the local file to copy. 
remote-file - Specifies the name to use on the remote computer. If not specified, the file is given the local-file name.

pwd

Displays the current directory on the remote computer.

Syntax: pwd

quit

Ends the FTP session with the remote computer and exits ftp.

Syntax: quit

quote

Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return. Quote is identical to literal.

Syntax: quote argument [ ...]

Parameter(s):
argument - Specifies the argument to send to the FTP server.

recv

Copies a remote file to the local computer using the current file transfer type. Recv is identical to get.

Syntax: recv remote-file [local-file]

Parameter(s):
remote-file - Specifies the remote file to copy. 
local-file - Specifies the name to use on the local computer. If not specified, the file is given the remote-file name.

remotehelp

Displays help for remote commands.

Syntax: remotehelp [command]

Parameter(s):
command - Specifies the name of the command about which you want help. If command is not specified, ftp displays a list of all remote commands.

rename

Renames remote files.

Syntax: rename filename newfilename

Parameter(s):
filename - Specifies the file you want to rename. 
newfilename - Specifies the new filename.

rmdir

Deletes a remote directory.

Syntax: rmdir directory

Parameter(s):
directory - Specifies the name of the remote directory to delete.

send

Copies a local file to the remote computer using the current file transfer type. Send is identical to put.

Syntax: send local-file [remote-file]

Parameter(s):
local-file - Specifies the local file to copy. 
remote-file - Specifies the name to use on the remote computer. If not specified, the file is given the local-file name.

status

Displays the current status of FTP connections and toggles.

Syntax: status

trace

Toggles packet tracing; trace displays the route of each packet when running an ftp command.

Syntax: trace

type

Sets or displays the file transfer type.

Syntax: type [type-name]

Parameter(s):
type-name - Specifies the file transfer type; the default is ASCII. If type-name is not specified, the current type is displayed.

Note
FTP supports two file transfer types, ASCII and binary image.

ASCII should be used when transferring text files. In ASCII mode, character conversions to and from the network standard character set are performed. For example, end-of-line characters are converted as necessary, based on the destination's operating system.

Binary should be used when transferring executable files. In binary mode, the file is moved byte-by-byte.

user

Specifes a user to the remote computer.

Syntax: user user-name [password] [account]

Parameter(s):
user-name - Specifies a user name with which to log in to the remote computer. 
password - Specifies the password for user-name. If not specified, but required, ftp prompts for the password. 
account - Specifies an account with which to log on to the remote computer. If account is not specified, but required, ftp prompts for the account.

verbose

Toggles verbose mode. If on, all ftp responses are displayed; when a file transfer completes, statistics regarding the efficiency of the transfer are also displayed. By default, verbose is on.

Syntax: verbose

Unix Command tar

The tar Command



The tar (i.e., tape archive) command is used to convert a group of files into an archive.

An archive is a single file that contains any number of individual files plus information to allow them to be restored to their original form by one or more extraction programs. Archives are convenient for storing files as well as for for transmitting data and distributing programs. Moreover, they are very easy to work with, often much more so than dealing with large numbers of individual files.

Although tar was originally designed for backups on magnetic tape, it can now be used to create archive files anywhere on a filesystem. Archives that have been created with tar are commonly referred to as tarballs.

Unlike some other archiving programs, and consistent with the Unix philosophy that each individual program should be designed to do only one thing but do it well, tar does not perform compression. However, it is very easy to compress archives created with tar by using specialized compression utilities.

tar's basic syntax is

tar option(s) archive_name file_name(s)

tar has numerous options, many of which are not frequently used. Unlike many commands, tar requires the use of at least one option, and usually two or more are necessary.

tar files are created by using both the -c and -f options. The former instructs tar to create an archive and the latter indicates that the next argument (i.e., piece of input data in a command) will be the name of the new archive file. Thus, for example, the following would create an archive file called file.tar from the three files named file1, file2 and file3 that are located in the current directory (i.e., the directory in which the user is currently working):

tar -cf file.tar file1 file2 file3

It it not absolutely necessary that the new file have the .tar extension; however, the use of this extension can be is very convenient because it allows the type of file to be visually identified. It is necessary, however, that the -f option be the final option in a sequence of contiguous, single-letter options; otherwise, the system will become confused as to the desired name for the new file and will use the next option in the sequence as the name.

The -v (i.e., verbose) option is commonly used together with the -c and -f options in order to display a list of the files that are included in the archive. In such case, the above example would become

tar -cvf file.tar file1 file2 file3

tar can also be used to make archives from the contents of one or more directories. The result is recursive; that is, it includes all objects (e.g., directories and files) within each level of directories. For example, the contents of two directories named dir1 and dir2 could be archived into a file named dir.tar with the following:

tar -cvf dir.tar dir1 dir2

It is often convenient to use tar with a wildcard (i.e., a character which can represent some specific class of characters or sequence of characters). The following example uses the star wildcard (i.e., an asterisk), which represents any character or sequence of characters, to create an archive of every object in the current directory:

tar -cf *

By default, tar creates an archive of copies of the original files and/or directories, and the originals are retained. However, they can be removed when using tar by adding the --remove-files option.

As it has no compression and decompression capabilities of its own, tar is commonly used in combination with an external compression utility. A very handy feature of the GNU version (which is standard on Linux) is the availability of options that will cause standard compression programs to compress a new archive file as soon as it has been created. They are -j (for bzip2), -z (for gzip) and -Z (for compress). Thus, for example, the following would create an archive named files.tar.bz2 of the files file4, file5 and file6 that is compressed using bzip2:

tar -cvjf files.tar.bz2 file4 file5 file6

tar can also be used for unpacking tar files. However, before doing this, there are several steps that should be taken. One is to confirm that sufficient space is available on the hard disk drive (HDD). Another is to move to an empty directory (which usually involves creating one with an appropriate name) to prevent the reconstituted files from cluttering up the current directory and overwriting any files or directories with same names that are in it. In addition, if the archive has been compressed, it must first be decompressed using the appropriate decompression program (which can usually be determined by the filename extension).

In order to unpack a tar file, the -x (for extract) and -f options are required. It is also common to add the -v option to provide a running listing of the files being unpacked. Thus, for example, to unpack the archive file.tar created in a previous example the following would be used:

tar -xvf file.tar

Just as options are available to allow three compression programs to automatically compress newly created tar files, the same options can be used to have the compression programs automatically decompress tar files prior to extraction. Thus, for instance, the following would decompress and extract the contents of the compressed archive files.tar.bz2 that was created in an above example:

tar -xjvf files.tar.bz2

Files can be added to an existing archive using the -r option. As is always the case with tar, it is also necessary to use the -f option to indicate that the following string (i.e., sequence of characters) is the name of the archive. For example, the following would append a file named file7 to file.tar:

tar -rf file.tar file7

The --delete option allows specified files to be completely removed from a tar file (except when the tar file is on magnetic tape). However, this is different from an extraction, as copies of the removed files are not made and placed in the current directory. Thus, for example, the files file1 and file2 can be removed from file.tar with the following:

tar -f file.tar --delete file1 file2

The -t option tells tar to list the contents of an uncompressed archive without performing an extraction. Thus, the following would list the contents of file.tar:

tar -tf file.tar

One of the very few options that can be used alone with tar is --help, which provides a relatively compact listing of the numerous options that are available. Another is --version, which shows the version number for the installed tar program as well as its copyright information.

การใช้งานคำสั่ง tar เป็นคำสั่งพื้นฐานมากๆ บนระบบ Linux หรือ Unix โดยผู้ใช้สามารถใช้งานคำสั่งนี้ผ่าน Terminal)สำหรับผู้ที่ชอบการบีบอัดไฟล์เื่พื่อ ง่ายต่อการจัดเก็บ

ผมคิดว่าพวกเราซึ่งเป็นนักพัฒนาน่าจะได้ใช้มันบ่อยมากๆ โดยเฉพาะตอน backup ลักษณะการทำงานของมันคล้ายกับพวก zip ไฟล์ที่เรารู้จักกันดี คำสั่ง tar ก็ทำงานคล้ายๆกับ zip ครับ ต่างกันนิดหน่อยตรงนี้ tar ไม่ได้ย่อ file มันแค่เอาไฟล์มาต่อๆ กันแล้วรวมเป็นไฟล์เดียว

การใช้งานก็ง่ายๆ ในกรณีที่เรามี folder ชื่อ Tools แล้วเราต้องการรวม file ทั้งหมดใน Tools รวมถึงตัว folder Tools ด้วย ก็ให้ใช้คำสั่งว่า

tar -cvf tools.tar Tools

  • c คือ ให้สร้าง file tar ขึ้นมา (create)
  • v คือ ให้แสดงชื่อด้วย
  • f tools.tar คือ ตำแหน่งที่เราต้องการให้สร้างไฟล์ (file) ขึ้นมา
  • Tools ก็คือ Folder ที่เป็นเป้าหมายในการรวมของเรา

หลังจากได้ tar มาแล้ว ถ้าต้องการแตกมันออกให้กลับมาเป็น Tools ก็ใช้คำสั่ง

tar -xvf xxx.tar

x คือ คำสั่งให้แตกไฟล์ออกมา (extract)

ในกรณีที่เราต้องการให้มันย่อไฟล์ด้วย แบบที่ zip ทำได้ ก็ให้เราเพิ่มตัว z ลงไป เช่น

tar -zcvf xxx.tar.gz Tools

ปกติเวลาที่เรามีการย่อไฟล์ด้วย เราจะตั้งนามสกุลให้เป็น tar.gz โดยตัว gz ย่อมาจาก gzip และ gzip ย่อมาจาก GNU Zip

เวลาจะแตกมันออกมาก็ใช้คำสั่ง

tar -zxvf tools.tar.gz



Wednesday, November 12, 2008