zoukankan      html  css  js  c++  java
  • 超级实用的 Linux/Unix FTP 下载上传文件命令详解

    FTP最重要的功能就是下载和上传文件,在我的实际应用中主要是去PROD环境上下载一些文件到UAT或者INTG进行测试,因为UAT和INTG环境中的数据并非被Release Team实时更新。下面的文章详细的讲解了 Linux/Unix FTP 的命令,属于超级实用,超级实战的好文。

    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.

    Use 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
    ftp user@ftp.example.com

    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.org

    Sample 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): ftp
    331 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: Download / Copy file

    To 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.pdf 

    Sample 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.gz

    Change Local Directory

    To change directory on your local system, enter:

    ftp> lcd /path/to/new/dir
    ftp> lcd /tmp

    Sample outputs:

    Local directory now: /tmp

    Print local directory:

    ftp> lpwd
    打印本地(Local)的路径

    Sample 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> lpwd
    打印FTP端的路径地址

    Sample outputs:

    Remote directory: /pub/FreeBSD

    Task: Download Multiple Files

    You 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 Prompting

    The 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 on
    ftp> mput *.php
    ftp> prompt off
    ftp> mget *.py

    Task: Delete File

    To delete a file in the current remote directory use delete command:

    ftp> delete fileName
    ftp> delete output.jpg 

    Task: Upload One File

    To copy one file at a time from the local systems to the remote ftp server, enter:

    ftp> put fileName

    In this example, upload logo.jpg, enter:

    ftp> put logo.jpg

    Task: Upload Multiple Files

    To 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: Set The Mode Of File Transfer

    To set the mode of file transfer to ASCII, enter:

    ftp> ascii

    Please note that ascii is the default and good for text files. To set the mode of file transfer to binary, enter:

    ftp> binary

    The 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 Server

    To open a connection with another ftp server, enter:

    ftp> open ftp.nixcraft.net.in

    The 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 Session

    Type quit or bye, enter:

    ftp> quit
    OR
    ftp> bye

    How Do I Find Out More Information About The FTP Commands?

    Type ? or help to get more information about the FTP commands:

    ftp> ?
    ftp> help

    To get a short description about each command, enter:

    ftp> help commandName
    ftp> help chmod
    ftp> help ls

    Sample outputs:

    ls      list contents of remote path
  • 相关阅读:
    [hdu3853]LOOPS(概率dp)
    [poj2096]Collecting Bugs(概率dp)
    lintcode-42-最大子数组 II
    lintcode-39-恢复旋转排序数组
    lintcode-36-翻转链表 II
    lintcode-34-N皇后问题 II
    lintcode-33-N皇后问题
    lintcode-32-最小子串覆盖
    lintcode-31-数组划分
    lintcode-30-插入区间
  • 原文地址:https://www.cnblogs.com/orientsun/p/2756275.html
Copyright © 2011-2022 走看看