我正在尝试上传多个文件,但我只是尝试单个文件上传练习,但我得到的文件找不到异常,我的任务是下。
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上传多个文件?
发布于 2014-04-06 20:18:58
您需要使用ad ftpurl地址文件夹/file.ext进行上传
同样,你使用一个简单的异常,你必须准确地处理异常,而不是一般的一个。
例如,ftp的完整路径必须为:
@"ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/" + filename + ext;
//ftp://ftp.yuvarukhisamaj.com/wwwroot/Shtri/yourimage.ext;解决了你的问题。
这是net的ftpclass中的一个常见错误。
https://stackoverflow.com/questions/22891286
复制相似问题