如何找到正确的uri以通过FTP上传文件

时间:2019-01-03 19:33:47

标签: c# ftp

我想将文件上传到QNAP,但是当我调用(FtpWebRequest)WebRequest.Create时出现错误,提示我的uri不正确。

private void UploadToFTP(string localFilePath)
    {
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://10.0.0.34:21/")
        request.UsePassive = true;
        request.Proxy = null;
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential("name", "pwd");
        byte[] fileContents;
        using (StreamReader sourceStream = new StreamReader(localFilePath))
        {
            fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        }
        request.ContentLength = fileContents.Length;

        using (Stream requestStream = request.GetRequestStream())
        {
            requestStream.Write(fileContents, 0, fileContents.Length);
        }

0 个答案:

没有答案