如何使用Windows应用程序将文件上传到Web服务器/ ftp服务器c#

我正在尝试使用Windows应用程序(c#)将文件上传到网络。我试过以下代码



I'm trying to upload a file to web using windows application(c#). I've tried this following code

private void uploadFile(string FTPAddress, string filePath, string username, string password)
        {
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + Path.GetFileName(filePath));

            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(username, password);
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;

            FileStream stream = File.OpenRead(filePath);
            byte[] buffer = new byte[stream.Length];

            stream.Read(buffer, 0, buffer.Length);
            stream.Close();

            Stream reqStream = request.GetRequestStream();
            reqStream.Write(buffer, 0, buffer.Length);
            reqStream.Close();

            MessageBox.Show("Uploaded Successfully");
        }





并在尝试此操作时出现以下错误





and getting this following error while trying this

Quote:

无法解析远程名称:'username'

The remote name could not be resolved: 'username'





任何人都可以指导我吗?

提前致谢。



Can anyone please guide me?
Thanks in advance.



 1 条回答

C#