C# FTP 上传下载
时间: 2023-10-19 07:26:35 浏览: 103
C#开发教程之FTP上传下载功能详解
要在C#中进行FTP上传和下载,您可以使用FTPWebRequest类来实现。
对于上传,您可以使用以下代码示例:
```csharp
public void UploadFile(string localFilePath, string remoteFileName)
{
string ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/" + remoteFileName;
FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpURI));
ftpRequest.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.UseBinary = true;
using (FileStream fileStream = File.OpenRead(localFilePath))
{
using (Stream ftpStream = ftpRequest.GetRequestStream())
{
byte[] buffer = new byte<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [C# FTP操作(上传、下载等……)](https://blog.csdn.net/u011465910/article/details/126563124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文