c# - Why when uploading file format 20%.jpg i'm getting exception? -
the reason % if i'm uploading 20 files , jpg no problems if 1 of files names example 20%.jpg or 50%.jpg can't upload them.
i can edit , see images on hard disk can't upload them.
now example test in files index 0 have: d:\5%.jpg txf , fn both contain: d:\5%.jpg
this top part of method upload files ftp server:
the exception happen when i'm calling method createdirectory in method.
private void stringarrayuploadfiles(object sender, doworkeventargs e) { try { foreach (string txf in files) { string fn = txf; backgroundworker bw = sender backgroundworker; fileinfo fileinfo = new fileinfo(txf); f.targetfolder = fileinfo.directoryname; f.targetfolder = path.getdirectoryname(txf); f.targetfolder = path.getfullpath(txf).replace(":", "").replace("\\", "/"); string filenameonly = path.getfilename(f.targetfolder); int index = txf.indexof(filenameonly); string left = txf.substring(0, index); f.targetfolder = path.getfullpath(left).replace(":", "").replace("\\", ""); createdirectory(f.targetfolder);
the variable f ftpsettings:
public class ftpsettings { public string host, username, password, targetfolder, sourcefile; public bool passive; public int port = 21; }
files string[]
the exception happen when i'm trying create directory file on ftp server. that's in method createdirectory i'm calling download method:
createdirectory(f.targetfolder);
this createdirectory method:
public void createdirectory(string newdirectory) { try { string ftphost = f.host + "/" + newdirectory; if (!ftphost.tolower().startswith("ftp://")) ftphost = "ftp://" + ftphost; ftprequest = (ftpwebrequest)webrequest.create(ftphost); ftprequest.credentials = new networkcredential(f.username, f.password); ftprequest.usebinary = true; ftprequest.usepassive = true; ftprequest.keepalive = true; ftprequest.method = webrequestmethods.ftp.makedirectory; ftpresponse1 = (ftpwebresponse)ftprequest.getresponse(); ftpresponse1.close(); ftprequest = null; } catch (exception ex) { console.writeline(ex.tostring()); } return; }
in variable newdirectory have: d that's fine i'm not sure % or why % make problem.
the exception heppen inside createdirectory method on line:
ftpresponse1 = (ftpwebresponse)ftprequest.getresponse(); system.net.webexception caught hresult=-2146233079 message=the remote server returned error: (550) file unavailable (e.g., file not found, no access). source=system stacktrace: @ system.net.ftpwebrequest.checkerror() @ system.net.ftpwebrequest.syncrequestcallback(object obj) @ system.io.stream.close() @ system.net.connectionpool.destroy(pooledstream pooledstream) @ system.net.connectionpool.putconnection(pooledstream pooledstream, object owningobject, int32 creationtimeout, boolean canreuse) @ system.net.ftpwebrequest.finishrequeststage(requeststage stage) @ system.net.ftpwebrequest.getresponse() @ ftp_progressbar.ftpprogress.createdirectory(string newdirectory) in c:\ftp_progressbar\ftp_progressbar\ftpprogress.cs:line 270 innerexception:
line 270 is:
ftpresponse1 = (ftpwebresponse)ftprequest.getresponse();
maybe in ftp uri special characters 20%
or other? try use httputility.urldecode
, httputility.urlencode
Comments
Post a Comment