c# - Can't open folders with spaces -
i have following code read items ftp-server:
internal list<ftpitem> openfolder(string foldername) { ftpwebrequest request = createftpwebrequest("ftp://myserver.com", foldername); request.method = webrequestmethods.ftp.listdirectorydetails; list<ftpitem> ftpitems = getftpitemsfromrequest(request); return ftpitems; } private list<ftpitem> getftpitemsfromrequest(ftpwebrequest ftpwebrequest) { list<ftpitem> ftpitems = new list<ftpitem>(); webresponse webresponse = ftpwebrequest.getresponse(); streamreader reader = new streamreader(webresponse.getresponsestream()); string line = reader.readline(); while (line != null) { ftpitems.add(new ftpitem(line)); line = reader.readline(); } reader.close(); webresponse.close(); return ftpitems; } private ftpwebrequest createftpwebrequest(params string[] url) { ftpwebrequest webrequest = (ftpwebrequest)webrequest.create(string.join("/", url)); webrequest.keepalive = false; webrequest.usebinary = true; webrequest.credentials = this.networkcredential; return webrequest; }
as long try open folder root/sub/subsub
works fine. if foldername contains space, error-message
no such file or directory
i tried replace space-character %20, doesn't work.
what have open folders contains spaces?
you forgot closing "/" @ end of url request. either append end of request:
ftpwebrequest webrequest = (ftpwebrequest)webrequest.create(string.join("/", url)+"/");
or add empty string url parameter:
ftpwebrequest request = createftpwebrequest("ftp://myserver.com", foldername,"");
Comments
Post a Comment