問題描述
我可以在 FTP 中提取 ZIP 文件并使用 C# 將此提取的文件放在同一位置嗎?
Can I extract the ZIP file in FTP and place this extracted file on the same location using C#?
推薦答案
不可能.
FTP 協議中沒有用于解壓縮服務器上文件的 API.
There's no API in the FTP protocol to un-ZIP a file on a server.
但是,除了 FTP 訪問之外,還具有 SSH 訪問的情況并不少見.如果是這種情況,您可以通過 SSH 連接并在服務器上執行 unzip
shell 命令(或類似命令)來解壓文件.
請參閱 C# 發送簡單的 SSH 命令.
Though, it's not uncommon that one, in addition to an FTP access, have also an SSH access. If that's the case, you can connect with the SSH and execute the unzip
shell command (or similar) on the server to decompress the files.
See C# send a simple SSH command.
如果需要,您可以使用 FTP 協議下載提取的文件(盡管如果您有 SSH 訪問權限,您也將擁有 SFTP 訪問權限.然后,使用 SFTP 而不是 FTP.).
If you need, you can then download the extracted files using the FTP protocol (Though if you have the SSH access, you will also have an SFTP access. Then, use the SFTP instead of the FTP.).
一些(極少數)FTP 服務器提供 API 以使用 SITE EXEC
命令(或類似命令)執行任意 shell(或其他)命令.但這真的非常罕見.你可以像上面的 SSH 一樣使用這個 API.
Some (very few) FTP servers offer an API to execute an arbitrary shell (or other) commands using the SITE EXEC
command (or similar). But that's really very rare. You can use this API the same way as the SSH above.
如果您想在本地下載和解壓縮文件,您可以在內存中進行,而無需將 ZIP 文件存儲到物理(臨時)文件中.有關示例,請參閱如何將存儲在 FTP 服務器上的 ZIP 文件中的數據導入 C# 中的數據庫.
If you want to download and unzip the file locally, you can do it in-memory, without storing the ZIP file to physical (temporary) file. For an example, see How to import data from a ZIP file stored on FTP server to database in C#.
這篇關于我們可以使用 C# 在 FTP 服務器中解壓縮文件嗎的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!