我想使用 ftp 帐户上传图像。我的代码是这样的。但是当我选择图像并提交时,它说“找不到文件'C:\Program Files (x86)\IIS Express\picture.jpg'。” 我知道我的图像在我的桌面上,我从那里选择。如果我手动复制我的图像这个 IIS 文件夹,它会上传,但这是不明智的。我必须在我想要的地方选择我的形象。但它正在 IIS Express 文件夹中查找。
[HttpPost, ValidateInput(false)]
public ActionResult Insert(Press model, HttpPostedFileBase uploadfile)
{
...........
...........
...........
...........
if (uploadfile.ContentLength > 0)
{
string fileName = Path.Combine(uploadfile.FileName);
var fileInf = new FileInfo(fileName);
var reqFtp =
(FtpWebRequest)
FtpWebRequest.Create(
new Uri("ftp://ftp.adres.com" + fileInf.Name));
reqFtp.Credentials = new NetworkCredential(username, password);
reqFtp.KeepAlive = false;
reqFtp.Method = WebRequestMethods.Ftp.UploadFile;
reqFtp.UseBinary = true;
reqFtp.ContentLength = uploadfile.ContentLength;
int bufferlength = 2048;
byte[] buff = new byte[bufferlength];
int contentLen;
FileStream fs = fileInf.OpenRead(); …Run Code Online (Sandbox Code Playgroud)