我正在尝试上传多个文件,但我只是尝试单个fileupload进行练习,但我发现文件未找到异常,我的任务就是如此。
private static void UploadFileToFtp(string source)
{
String ftpurl = @"ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/"; //“@ftpurl”; // e.g. ftp://serverip/foldername/foldername
String ftpusername = "yuvarukh";//“@ftpusername”; // e.g. username
String ftppassword = "CXhV5Rzeu";//“@ftppassword”; // e.g. password
try
{
string filename = Path.GetFileName(source);
string ftpfullpath = ftpurl;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
catch (Exception ex)
{
throw ex;
}
}
protected void Btn1_Click(object sender, EventArgs e)
{
String sourcefilepath = FileUpload1.FileName;
UploadFileToFtp(sourcefilepath);
}
错误详情为An Exception of type “System.IO.FileNotFoundException” Occurred in Bshadow.DLL but was not handle in usercode
。
其他信息:找不到文件C:\Programfiles\Microsoft Visual Studio 8\IDE\dd.jpg
如何使用fileUploaders通过FTP上传多个文件?
答案 0 :(得分:0)
您需要使用ad ftpurl地址文件夹/ file.ext进行上传
此外,您使用一个简单的例外,您必须处理完全不正常的异常。
例如,ftp的完整路径必须是:
@"ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/" + filename + ext;
//ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/yourimage.ext;
解决您的问题。
这是net的ftpclass中的常见错误。