c# - FileNotFoundException With FTP -
i trying upload files more 1 trying single fileupload practice getting file not found exception task under.
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); }
error details an exception of type “system.io.filenotfoundexception” occurred in bshadow.dll not handle in usercode
. additional information: not find file c:\programfiles\microsoft visual studio 8\ide\dd.jpg
how can upload multiple files fileuploaders via ftp?
you need use ad ftpurl address folder/file.ext upload
also use simple exception must handling exception not one.
in example full path ftp must :
@"ftp://ftp.yuvarukhisamaj.com/wwwroot/shtri/" + filename + ext; //ftp://ftp.yuvarukhisamaj.com/wwwroot/shtri/yourimage.ext;
that fix issue.
it common error in ftpclass of net.
Comments
Post a Comment