如何使用Linux FTP命令传输文件

FTP(文件传输协议)是用于与远程网络之间传输文件的标准网络协议。

在本教程中,我们将通过实际示例向您展示如何使用Linux ftp命令

在大多数情况下,您将使用桌面FTP客户端连接到远程服务器并下载或上载文件。但是,ftp当您在没有GUI的服务器上工作并且希望通过FTP将文件传输到远程服务器或从远程服务器传输文件时,该命令很有用

在你开始之前

通过ftp传输数据时,连接未加密。要进行安全的数据传输,请使用SCP。

为了能够传输文件,您必须至少具有对源文件的读取权限和对目标系统的写入权限。

传输大文件时,建议屏幕或tmux会话中运行ftp命令。

运行该ftp命令的目录是本地工作目录。

建立FTP连接

  1. 要打开与远程系统的ftp连接,请使用ftp命令后跟远程服务器IP地址域名

    ftp 192.168.42.77

    1. 如果建立连接,将显示确认消息,系统将提示您输入FTP用户名,在此示例中,FTP用户名为linuxidc:
    220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------  220-You are user number 1 of 50 allowed.  220-Local time is now 21:35. Server port: 21.  220-This is a private system - No anonymous login  220-IPv6 connections are also welcome on this server.  220 You will be disconnected after 15 minutes of inactivity.  Name (192.168.42.77:localuser): linuxidc

    You may see a different confirmation message depending on the FTP service running on the remote server.

  2. 输入用户名后,系统将提示您输入密码

    Password:

    1. 如果密码正确,远程服务器将显示确认消息和ftp>提示。
    230 OK. Current restricted directory is /  Remote system type is UNIX.  Using binary mode to transfer files.  ftp>

如果您访问的FTP服务器接受匿名ftp帐户,并且您想以匿名用户anonymous身份登录,请使用用户名和电子邮件地址作为密码。

常用FTP命令

许多FTP命令与您在Linux shell提示符中键入的命令类似或相同。

以下是一些最常见的FTP命令

  • help或?- 列出所有可用的FTP命令。
  • cd – 更改远程计算机上的目录。
  • lcd – 更改本地计算机上的目录。
  • ls – 列出当前远程目录中的文件和目录的名称。
  • mkdir – 在当前远程目录中创建一个新目录。
  • pwd – 打印远程计算机上的当前工作目录。
  • delete – 删除当前远程目录中的文件。
  • rmdir- 删除当前远程目录中的目录。
  • get – 将一个文件从远程复制到本地计算机。
  • mget – 将多个文件从远程复制到本地计算机。
  • put – 将一个文件从本地复制到远程计算机。
  • mput – 将一个文件从本地复制到远程计算机。

使用FTP命令下载文件

登录后,您当前的工作目录是远程用户主目录。

使用该ftp命令下载文件时,文件将下载到您键入ftp命令的目录中。

如果要将文件下载到另一个本地目录,请使用该lcd命令切换到该目录。

假设我们要将文件下载到~/ftp_downloads目录:

lcd ~/ftp_downloads

要从远程服务器下载单个文件,请使用该get命令。例如,要下载名为的文件,请backup.zip使用以下命令:

get backup.zip

输出应该如下所示:

200 PORT command successful  150-Connecting to port 60609  150 6516.9 kbytes to download  226-File successfully transferred  226 2.356 seconds (measured here), 2.70 Mbytes per second  6673256 bytes received in 2.55 seconds (2.49 Mbytes/s)

要一次下载多个文件,请使用该mget命令。您可以提供单个文件名列表或使用通配符。

mget backup1.zip backup2.zip

下载多个文件时,系统将提示您确认每个文件。

mget backup1.zip? y  200 PORT command successful  150 Connecting to port 52231  226-File successfully transferred  226 0.000 seconds (measured here), 31.51 Kbytes per second  14 bytes received in 0.00058 seconds (23.6 kbytes/s)  mget backup2.zip? y  200 PORT command successful  150-Connecting to port 59179  150 7.2 kbytes to download  226-File successfully transferred  226 0.000 seconds (measured here), 16.68 Mbytes per second  7415 bytes received in 0.011 seconds (661 kbytes/s)

完成从远程FTP服务器下载文件后,用bye或关闭连接quit。

quit

221-Goodbye. You uploaded 0 and downloaded 6544 kbytes.  221 Logout.

使用FTP命令上载文件

要将文件从本地目录上载到远程FTP服务器,请使用以下put命令:

put image.jpg

输出应该如下所示:

200 PORT command successful  150 Connecting to port 34583  226-File successfully transferred  226 0.849 seconds (measured here), 111.48 Kbytes per second  96936 bytes sent in 0.421 seconds (225 kbytes/s)

如果要上载不在当前工作目录中的文件,请使用该文件的绝对路径

要将多个文件从本地目录上载到远程FTP服务器,请使用以下mput命令:

mput image1.jpg image2.jpg

mput image1.jpg? y  200 PORT command successful  150 Connecting to port 41075  226-File successfully transferred  226 1.439 seconds (measured here), 102.89 Kbytes per second  151586 bytes sent in 1.07 seconds (138 kbytes/s)  mput image2.jpg? y  200 PORT command successful  150 Connecting to port 40759  226-File successfully transferred  226 1.727 seconds (measured here), 111.75 Kbytes per second  197565 bytes sent in 1.39 seconds (138 kbytes/s)

上传多个文件时,系统将提示您确认要上传的每个文件。

完成上传文件到远程FTP服务器后,用bye或关闭连接quit。

结论

在本教程中,您学习了如何使用ftp命令下载文件并将文件上载到远程FTP服务器。FTP(文件传输协议)是用于与远程网络之间传输文件的标准网络协议。

在本教程中,我们将通过实际示例向您展示如何使用Linux ftp命令。

在大多数情况下,您将使用桌面FTP客户端连接到远程服务器并下载或上载文件。但是,ftp当您在没有GUI的服务器上工作并且希望通过FTP将文件传输到远程服务器或从远程服务器传输文件时,该命令很有用。

在你开始之前

通过ftp传输数据时,连接未加密。要进行安全的数据传输,请使用SCP。

为了能够传输文件,您必须至少具有对源文件的读取权限和对目标系统的写入权限。

传输大文件时,建议在屏幕或tmux会话中运行ftp命令。

运行该ftp命令的目录是本地工作目录。

建立FTP连接

  1. 要打开与远程系统的ftp连接,请使用ftp命令后跟远程服务器IP地址或域名:

    ftp 192.168.42.77

    1. 如果建立连接,将显示确认消息,系统将提示您输入FTP用户名,在此示例中,FTP用户名为linuxidc:
    220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------  220-You are user number 1 of 50 allowed.  220-Local time is now 21:35. Server port: 21.  220-This is a private system - No anonymous login  220-IPv6 connections are also welcome on this server.  220 You will be disconnected after 15 minutes of inactivity.  Name (192.168.42.77:localuser): linuxidc

    You may see a different confirmation message depending on the FTP service running on the remote server.

  2. 输入用户名后,系统将提示您输入密码:

    Password:

    1. 如果密码正确,远程服务器将显示确认消息和ftp>提示。
    230 OK. Current restricted directory is /  Remote system type is UNIX.  Using binary mode to transfer files.  ftp>

如果您访问的FTP服务器接受匿名ftp帐户,并且您想以匿名用户anonymous身份登录,请使用用户名和电子邮件地址作为密码。

常用FTP命令

许多FTP命令与您在Linux shell提示符中键入的命令类似或相同。

以下是一些最常见的FTP命令

  • help或?- 列出所有可用的FTP命令。
  • cd – 更改远程计算机上的目录。
  • lcd – 更改本地计算机上的目录。
  • ls – 列出当前远程目录中的文件和目录的名称。
  • mkdir – 在当前远程目录中创建一个新目录。
  • pwd – 打印远程计算机上的当前工作目录。
  • delete – 删除当前远程目录中的文件。
  • rmdir- 删除当前远程目录中的目录。
  • get – 将一个文件从远程复制到本地计算机。
  • mget – 将多个文件从远程复制到本地计算机。
  • put – 将一个文件从本地复制到远程计算机。
  • mput – 将一个文件从本地复制到远程计算机。

使用FTP命令下载文件

登录后,您当前的工作目录是远程用户主目录。

使用该ftp命令下载文件时,文件将下载到您键入ftp命令的目录中。

如果要将文件下载到另一个本地目录,请使用该lcd命令切换到该目录。

假设我们要将文件下载到~/ftp_downloads目录:

lcd ~/ftp_downloads

要从远程服务器下载单个文件,请使用该get命令。例如,要下载名为的文件,请backup.zip使用以下命令:

get backup.zip

输出应该如下所示:

200 PORT command successful  150-Connecting to port 60609  150 6516.9 kbytes to download  226-File successfully transferred  226 2.356 seconds (measured here), 2.70 Mbytes per second  6673256 bytes received in 2.55 seconds (2.49 Mbytes/s)

要一次下载多个文件,请使用该mget命令。您可以提供单个文件名列表或使用通配符。

mget backup1.zip backup2.zip

下载多个文件时,系统将提示您确认每个文件。

mget backup1.zip? y  200 PORT command successful  150 Connecting to port 52231  226-File successfully transferred  226 0.000 seconds (measured here), 31.51 Kbytes per second  14 bytes received in 0.00058 seconds (23.6 kbytes/s)  mget backup2.zip? y  200 PORT command successful  150-Connecting to port 59179  150 7.2 kbytes to download  226-File successfully transferred  226 0.000 seconds (measured here), 16.68 Mbytes per second  7415 bytes received in 0.011 seconds (661 kbytes/s)

完成从远程FTP服务器下载文件后,用bye或关闭连接quit。

quit

221-Goodbye. You uploaded 0 and downloaded 6544 kbytes.  221 Logout.

使用FTP命令上载文件

要将文件从本地目录上载到远程FTP服务器,请使用以下put命令:

put image.jpg

输出应该如下所示:

200 PORT command successful  150 Connecting to port 34583  226-File successfully transferred  226 0.849 seconds (measured here), 111.48 Kbytes per second  96936 bytes sent in 0.421 seconds (225 kbytes/s)

如果要上载不在当前工作目录中的文件,请使用该文件的绝对路径。

要将多个文件从本地目录上载到远程FTP服务器,请使用以下mput命令:

mput image1.jpg image2.jpg

mput image1.jpg? y  200 PORT command successful  150 Connecting to port 41075  226-File successfully transferred  226 1.439 seconds (measured here), 102.89 Kbytes per second  151586 bytes sent in 1.07 seconds (138 kbytes/s)  mput image2.jpg? y  200 PORT command successful  150 Connecting to port 40759  226-File successfully transferred  226 1.727 seconds (measured here), 111.75 Kbytes per second  197565 bytes sent in 1.39 seconds (138 kbytes/s)

上传多个文件时,系统将提示您确认要上传的每个文件。

完成上传文件到远程FTP服务器后,用bye或关闭连接quit。

结论

在本教程中,您学习了如何使用ftp命令下载文件并将文件上载到远程FTP服务器。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 如何使用Linux FTP命令传输文件 https://www.lizi.tw/soft/15548.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

如何使用Linux FTP命令传输文件-海报

分享本文封面