使用SFTP通过PERL/CGI.pm将图像从HTML表单传输到远程linux服务器 [英] Using SFTP to transfer images from HTML form to remote linux server using PERL/CGI.pm
问题描述
这是一个学校项目,导师不知道如何编写代码.
This is a school project, and the instructor has no knowledge of how to write the code.
我正在使用 CGI
,并且正在尝试传输文件而不使用 Net :: FTP
或
I am using CGI
and I am attempting to transfer a file without using Net::FTP
or Net::SFTP
since the server I am attempting to transfer it to will not allow connections from these services. I have written the HTML form and I am able to grab the name of the file uploaded through CGI
.
是否可以使用bash在驻留在Linux服务器上的Perl脚本中的Perl脚本中使用SFTP命令来传输通过HTML表单上传的文件?
Is it possible to use the SFTP command within a Perl script that resides on a Linux server using bash to transfer a file uploaded through an HTML form?
如果有人知道执行此操作的方法,请发布代码,以便我可以对其进行修改并插入到我的脚本中.
If anyone knows a way to do it please post the code so I can modify it and insert into my script.
推荐答案
use CGI qw(:standard);
use File::Basename;
my ( $name, $path, $extension) = fileparse ( $productimage, '..*' );
$productimage = $name . $extension;
$productimage =~ tr/ /_/; $productimage =~ s/[^$safechars]//g;
if ( $productimage =~/^([$safechars]+)$/ ) {
$productimage = $1;
} else {
die "Filename contains invalid characters";
}
$fh = upload('image');
$uploaddir = "../../.hidden/images";
open ( UPLOADFILE, ">$uploaddir/$productimage" )
or die "$!"; binmode UPLOADFILE;
while (<$fh>) {
print UPLOADFILE;
}
close UPLOADFILE;
这是我用来将文件上传到服务器的代码.
This is the code I used to upload the file into the server.
这篇关于使用SFTP通过PERL/CGI.pm将图像从HTML表单传输到远程linux服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!