我在这里问是否有任何C#函数可以让我通过某个FtpWebRequest
或发现最后上传文件的目录Stream
,以便我以后可以将它存储在MySQL数据库中?
这个功能:
public static string uploadftp(string filename, string ftpserver, string user, string pass)
{
System.Net.FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpserver);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(user, pass);
Stream ftpStream = request.GetRequestStream();
FileStream file = File.OpenRead(filename);
int length = Convert.ToInt32(file.Length);
byte[] buffer = new byte[length];
int bytesRead = 0;
do
{
bytesRead = file.Read(buffer, 0, length);
ftpStream.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
//supposed get directory code
ftpStream.Close();
//return directory
}