0

我在这里问是否有任何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
    }
4

1 回答 1

0

您可以对 FTP 文件夹的根文件夹使用文件监视器。上传文件时会触发该文件名,您可以将其存储在mysql中。

于 2012-06-13T11:10:56.653 回答