如何使用C#提取ftp服务器上存在的zip文件 [英] How to extract zip file which exist on ftp server using C#
本文介绍了如何使用C#提取ftp服务器上存在的zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 ftplib 使用以下代码上传ftp服务器上的文件
I am using ftplib for uploading files on ftp server using following code
FtpConnection ftp = new FtpConnection(serverip, ftpuser, ftppassword);
ftp.Open();
ftp.Login();
ftp.SetCurrentDirectory("domain/wwwroot");
void CreateDirOnFtp(string sDir, FtpConnection ftp)
{
try
{
foreach (string f in Directory.GetFiles(sDir))
{
Uri uri = new Uri(f);
ftp.PutFile(f, System.IO.Path.GetFileName(uri.LocalPath));
}
foreach (string d in Directory.GetDirectories(sDir))
{
string dirname = new DirectoryInfo(d).Name;
if (!ftp.DirectoryExists(dirname))
{
ftp.CreateDirectory(dirname);
}
ftp.SetCurrentDirectory(dirname);
CreateDirOnFtp(d, ftp);
}
}
catch (System.Exception e)
{
}
}
但是这段代码没有遍历所有目录,因此错过了ftp服务器上的一些目录和文件。
所以我决定在ftp上传zip文件并在ftp服务器上解压缩,但我找不到任何方法来提取ftp服务器上存在的文件。
我该怎么做?或者在ftp服务器上上传多个目录和文件的任何其他更好的方法
But this code is not iterating through all directories so missing some directories and files on ftp server.
so i decided to upload zip file on ftp and extract it on ftp server but I cant find any way to extract file which exist on ftp server.
How can i do this? Or any other better way to upload mutiple directories and file on ftp server
推荐答案
这不起作用。您不能将FTP服务器视为本地连接的文件系统。你必须在本地提取.ZIP文件,然后将结果文件上传到它们应该是一个一个的位置。
This isn't going to work. You cannot treat an FTP server like is was a locally attached file system. You have to extract the .ZIP file locally, then upload the resulting files to where they are supposed to be one-by-one.
你好,
要解压缩文件,有一个名为Shell32.dll的系统dll,您可以在C:\ WINDOWS \ system@athell32.dll位置找到它(对于32位系统) 。在您的应用程序中添加此参考,并按照以下链接进行编码。
http://prateektiwari.wordpress.com/2011/08/10/zip-and-unzip-files-using-shell- 32分量/ [ ^ ]
轻松压缩/解压缩文件 [ ^ ]
快乐编码:)< br $>
问候,
Manoj
Hi,
To unzip files there is a system dll called "Shell32.dll" which you can find in the location "C:\WINDOWS\system32\shell32.dll" (for 32-bit systems). Add a reference of this to your application and follow the coding like the below links.
http://prateektiwari.wordpress.com/2011/08/10/zip-and-unzip-files-using-shell-32-component/[^]
Easily zip / unzip files using Windows Shell32[^]
Happy coding :)
Regards,
Manoj
这篇关于如何使用C#提取ftp服务器上存在的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文