使用C#进行FTP上传 [英] FTP upload using C#
本文介绍了使用C#进行FTP上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个ftp上传,从我的本地上传文件到ftp文件夹,但我的问题是,我需要刷新FTP文件夹来查看我上传的文件。
请帮忙。
我的尝试:
So I have this ftp upload, upload file from my local to ftp folder, but my problem is, I need to refresh the FTP Folder to view my uploaded file.
Pls help.
What I have tried:
using System.Net;
using System.IO;
//Create FTP request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(ftpAdd + "/" + Path.GetFileName(filePath));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
//Load the file
FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
request = null;
MessageBox.Show("Uploaded Successfully");
推荐答案
使用FileZilla可能: Filezilla:如何自动刷新FTP文件夹 - 超级用户 [ ^ ]
With FileZilla it is possible: Filezilla: How to refresh a FTP folder automatically - Super User[^]
这篇关于使用C#进行FTP上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文