从FTP服务器检索上次上载的文件目录

时间:2012-06-13 11:06:28

标签: c# file ftp directory discover

我在这里询问是否有任何C#函数允许我通过某个FtpWebRequestStream发现上次上传文件的目录,因此我可以将其存储在MySQL中数据库以后?

感谢您的帮助。

JoãoBorrego

编辑:

此功能:

    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
    }

1 个答案:

答案 0 :(得分:0)

您可以将文件观察程序用作FTP文件夹的根文件夹。当使用文件名上传文件时会触发它,你可以将它存储在mysql中。