Rackspace Cloud Files:使用Linux/Unix FTP命令上传文件

时间:2020-01-09 10:40:48  来源:igfitidea点击:

如何在递归模式下使用标准Linux或Unix ftp客户端将文件上传到Rackspace云文件存储?

Rackspace云文件是一种在线存储,可以使用Web服务界面RESTful API或在线控制面板进行访问。
这是使用OpenStack技术构建的,因此以下教程应适用于任何支持OpenStack的云解决方案。

前提条件

  • ftp-cloudfs基于Python的FTP接口,用于Rackspace Cloud Files和OpenStack Swift。这充当Rackspace云的代理。默认情况下,ftp-cloudfs将侦听端口2021,并且您可以使用任何标准ftp客户端连接到此端口,以上传/下载文件或创建容器。
  • pip命令安装ftp-cloudfs。
  • Rackspace API用户名和密码。

安装ftp-cloudfs

执行以下命令(请参阅如何设置和安装pip):

$ pip install ftp-cloudfs

输出示例:

Downloading/unpacking ftp-cloudfs
  Downloading ftp-cloudfs-0.18.tar.gz
  Running setup.py egg_info for package ftp-cloudfs
Downloading/unpacking pyftpdlib (from ftp-cloudfs)
  Downloading pyftpdlib-0.7.0.tar.gz (94kB): 94kB downloaded
  Running setup.py egg_info for package pyftpdlib
 
    You might want to install pysendfile module to speedup transfers:
    http://code.google.com/p/pysendfile/
Downloading/unpacking python-cloudfiles (from ftp-cloudfs)
  Downloading python-cloudfiles-1.7.10.tar.gz (397kB): 397kB downloaded
  Running setup.py egg_info for package python-cloudfiles
    warning: no previously-included files found matching 'python_cloudfiles.egg-info'
Downloading/unpacking python-daemon (from ftp-cloudfs)
  Downloading python-daemon-1.6.tar.gz (41kB): 41kB downloaded
  Running setup.py egg_info for package python-daemon
Downloading/unpacking python-memcached (from ftp-cloudfs)
  Downloading python-memcached-1.48.tar.gz (40kB): 40kB downloaded
  Running setup.py egg_info for package python-memcached
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./py_virtual/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg (from python-daemon->ftp-cloudfs)
Downloading/unpacking lockfile>=0.9 (from python-daemon->ftp-cloudfs)
  Downloading lockfile-0.9.1.tar.gz
  Running setup.py egg_info for package lockfile
Installing collected packages: ftp-cloudfs, pyftpdlib, python-cloudfiles, python-daemon, python-memcached, lockfile
  Running setup.py install for ftp-cloudfs
    changing mode of build/scripts-2.6/ftpcloudfs from 644 to 755
    changing mode of /home/Hyman/py_virtual/bin/ftpcloudfs to 755
  Running setup.py install for pyftpdlib
 
    You might want to install pysendfile module to speedup transfers:
    http://code.google.com/p/pysendfile/
  Running setup.py install for python-cloudfiles
    warning: no previously-included files found matching 'python_cloudfiles.egg-info'
  Running setup.py install for python-daemon
  Running setup.py install for python-memcached
  Running setup.py install for lockfile
Successfully installed ftp-cloudfs pyftpdlib python-cloudfiles python-daemon python-memcached lockfile
Cleaning up...

您还需要安装Python接口来发送文件以加快文件操作:

$ pip install py-sendfile pysendfile

输出示例:

Downloading/unpacking py-sendfile
  Downloading py-sendfile-1.2.3.tar.gz
  Running setup.py egg_info for package py-sendfile
Downloading/unpacking pysendfile
  Downloading pysendfile-2.0.0.tar.gz
  Running setup.py egg_info for package pysendfile
Installing collected packages: py-sendfile, pysendfile
  Running setup.py install for py-sendfile
    building 'sendfile' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c sendfilemodule.c -o build/temp.linux-x86_64-2.6/sendfilemodule.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6/sendfilemodule.o -o build/lib.linux-x86_64-2.6/sendfile.so
  Running setup.py install for pysendfile
    building 'sendfile' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c sendfilemodule.c -o build/temp.linux-x86_64-2.6/sendfilemodule.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6/sendfilemodule.o -o build/lib.linux-x86_64-2.6/sendfile.so
Successfully installed py-sendfile pysendfile
Cleaning up...

如何启动ftp-cloudfs代理服务器?

只需执行以下命令:

$ ftpcloudfs

默认情况下ftpcloudfs将侦听127.0.0.1:2021。
您可以使用以下命令对此进行验证。
确保ftpcloudfs已启动,并且可以使用ps命令查看它:

$ ps aux | grep ftpcloudfs

输出示例:

Hyman    32314  0.2  0.1  43992  9408 ?        S    22:28   0:00 /home/Hyman/py_virtual/bin/python /home/Hyman/py_virtual/bin/ftpcloudfs
Hyman    32315  0.0  0.1  52188  9268 ?        S    22:28   0:00 /home/Hyman/py_virtual/bin/python /home/Hyman/py_virtual/bin/ftpcloudfs
Hyman    32322  0.0  0.1  43988  8840 ?        S    22:28   0:00 /home/Hyman/py_virtual/bin/python /home/Hyman/py_virtual/bin/ftpcloudfs
Hyman    32333  0.0  0.0   8996   836 pts/8    S+   22:28   0:00 grep --color ftpcloudfs

使用netstat命令验证ftpcloudfs是否已打开端口2021,请运行:

$ netstat -tulpn | grep :2021

输出示例:

(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:2021          0.0.0.0:*               LISTEN      32314/python

如何使用ftp客户端通过ftpcloudfs代理连接到Rackspace云?

您需要在2021端口连接到ftp代理IP 127.0.0.1:

+-------------+       +------------------+           +-----------------------+
|  ftp client | --->  | ftpcloudfs proxy |     | Rackspace cloud files |
+-------------+       +------------------+           +-----------------------+
                      Proxy IP: 127.0.0.1
                      Proxy Port: 2021

执行ftp命令,如下所示:

ftp 127.0.0.1 2021

您也可以使用lftp命令,如下所示:

lftp -u USERNAME -p 2021 127.0.0.1
lftp -u USERNAME,PASSWORD -p 2021 127.0.0.1
lftp -e 'ftp-command1; ftp-command2;exit;' -u USERNAME,PASSWORD -p 2021 127.0.0.1
lftp -e 'ls;exit;' -u USERNAME,PASSWORD -p 2021 127.0.0.1

示例会话示例

像Linux和Unix之类的操作系统附带ftp客户端,该客户端允许用户与远程网络站点进行文件传输:

ftp 127.0.0.1 2021

输出示例:

Connected to 127.0.0.1.
220 Rackspace Cloud Files 0.18 using pyftpdlib 0.7.0 ready.
Name (127.0.0.1:Hyman): theitroad
500 Command "AUTH" not understood.
500 Command "AUTH" not understood.
SSL not available
331 Username ok, send password.
Password: HIIDENPASSWORD
230 Welcome theitroad
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 Active data connection established.
125 Data connection already open. Transfer starting.
drwxr-xr-x 745 theitroad theitroad 42698582 Oct 29 17:08 images.theitroad.local
drwxr-xr-x 100 theitroad theitroad   497143 Oct 29 17:08 static
drwxr-xr-x 555 theitroad theitroad 22378320 Oct 29 17:08 pdfs
drwxr-xr-x   1 theitroad theitroad        0 Oct 29 17:08 videos
drwxr-xr-x   1 theitroad theitroad        0 Oct 29 17:08 wpuploads
drwxr-xr-x 1346 theitroad theitroad 67375928 Oct 29 17:08 images
226 Transfer complete.

有关如何使用ftp命令的更多信息,请参见如何使用ftp命令上传/下载文件。

关于GUI ftp客户端的说明

如果您不想执行命令,请使用Firefox之类的浏览器,然后在网址栏输入以下内容:

ftp://127.0.0.1:2021/
ftp://USERNAME:[email protected]:2021/

您也可以使用任何基于GUI的标准FTP客户端。

关于ftp的说明

您可能要使用sftp-cloudfs,它为Rackspace云文件和Open Stack对象存储(Swift)提供SFTP(安全ftp)接口,如此处所述。
请继续关注sftp-cloudfs教程。

如何从云文件下载文件?

您可以使用URL通过cdn url通过公共互联网访问此容器中的文件,如下所示:

http://8173579aa04ea33f3314-2bd3e6c481b4a486fea8b805a638363d.r25.cf2.rackcdn.com/file.txt