我想从普通的 http 链接下载一个大文件到 ftp 服务器(在 ubuntu 下),而不在本地存储文件(因为我的本地存储太小)。
你有什么想法如何用 wget 或一个小的 perl 脚本来做到这一点?(我在本地机器上没有 sudo 权限)。
wget -O - http://website.com/hugefile.zip | perl -MNet::FTP -e 'my $ftp = Net::FTP->new("ftp.example.com"); $ftp->login("user", "pass"); $ftp->put(\*STDIN, "hugefile.zip");'
当然,您也可以将其放入文件 ( ftpupload.pl
) 中并运行它。
#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
my $ftp = Net::FTP->new("ftp.example.com"); # connect to FTP server
$ftp->login("user", "pass"); # login with your credentials
# Because of the pipe we get the file content on STDIN
# Net::FTP's put is able to handle a pipe as well as a filehandle
$ftp->put(\*STDIN, "hugefile.zip");
像这样运行它:
wget -O - http://website.com/hugefile.zip | perl ftpupload.pl
当然,还有一个 CPAN 模块,它使 FTP 的生活变得轻松:
http://search.cpan.org/search?mode=module&query=Net%3A%3AFTP
WWW::Mechanize 查找文件、跟踪链接等。
有了这些模块,我认为您可以解决您的问题。
您可以尝试使用wput。它不是很知名的工具,但我认为你可以使用它。
使用 wget 的输出文档选项
wget -O /dev/null http://foo.com/file.uuu
从 wget 的手册页:
"-O file
--output-document=file
The documents will not be written to the appropriate files, but all will be
concatenated together and written to file. If - is used as file, documents will be
printed to standard output, disabling link conversion. (Use ./- to print to a file
literally named -.)
Use of -O is not intended to mean simply "use the name file instead of the
one in the URL;" rather, it is analogous to shell redirection: wget -O file http://foo is
intended to work like wget -O - http://foo > file; file will be truncated immediately,
and all downloaded content will be written there."
但是,我看不出这样做的目的是什么