"Permission Denied" 正在将 HTTP 发布的文件从 IE 上传到 SFTP
"Permission Denied" while uploading an HTTP-posted file from IE to SFTP
下面是我在 ftp 上上传文件的 C# 代码,我正在使用 Renci.SshNet.dll
连接到 sftp。
string Address = MyConfigDictionary.GetDictionary["SFTP_Address"].ToString();
int Port = 22;
string UserName = "myusername";
string Password = "mypassword";
string FolderName = "MyFolder";
using (SftpClient client = new SftpClient(Address, Port, UserName, Password))
{
client.Connect();
client.ChangeDirectory(FolderName + @"/");
client.BufferSize = 4 * 1024;
client.UploadFile(this.GetCmp<FileUploadField>("FileUpload").PostedFile.InputStream, "/" + FolderName + "/" + this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName, null);
client.Disconnect();
}
该代码在 Firefox 和 Chrome 中运行良好,但在 IE 中不起作用。(我正在 IE 10 中测试)。我在 IE 中得到 "Permission Denied"。
我在这里缺少什么 IE ?
得到答案:
当尝试使用 IE 上传文件时,它使用我的文件名 C:\Users\user_name\Downloads\myfile.csv
而不是 myfile.csv
所以替换了this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName
上面 client.UploadFile(..)
中的 Path.GetFileName(this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName)
。
下面是我在 ftp 上上传文件的 C# 代码,我正在使用 Renci.SshNet.dll
连接到 sftp。
string Address = MyConfigDictionary.GetDictionary["SFTP_Address"].ToString();
int Port = 22;
string UserName = "myusername";
string Password = "mypassword";
string FolderName = "MyFolder";
using (SftpClient client = new SftpClient(Address, Port, UserName, Password))
{
client.Connect();
client.ChangeDirectory(FolderName + @"/");
client.BufferSize = 4 * 1024;
client.UploadFile(this.GetCmp<FileUploadField>("FileUpload").PostedFile.InputStream, "/" + FolderName + "/" + this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName, null);
client.Disconnect();
}
该代码在 Firefox 和 Chrome 中运行良好,但在 IE 中不起作用。(我正在 IE 10 中测试)。我在 IE 中得到 "Permission Denied"。
我在这里缺少什么 IE ?
得到答案:
当尝试使用 IE 上传文件时,它使用我的文件名 C:\Users\user_name\Downloads\myfile.csv
而不是 myfile.csv
所以替换了this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName
上面 client.UploadFile(..)
中的 Path.GetFileName(this.GetCmp<FileUploadField>("FileUpload").PostedFile.FileName)
。