c# - FTP over SSL issue -
c# - FTP over SSL issue -
i'm having issue uploading file ftp site on ssl specific directory. i'm using system.net.ftpwebrequest class purpose. upload going through fine. file dropped home directory. thought might doing wrong? appreciate help.
public bool uploadfile(string srcfilepath, string destfilepath = null) { if (string.isnullorwhitespace(srcfilepath)) throw new argumentnullexception("source filepath."); if (string.isnullorwhitespace(destfilepath)) destfilepath = path.getfilename(srcfilepath); uri serveruri = geturi(destfilepath); //// serveruri should start ftp:// scheme. if (serveruri.scheme != uri.urischemeftp) homecoming false; // object used communicate server. ftpwebrequest request = createftprequest(serveruri, webrequestmethods.ftp.uploadfile); // read file byte array streamreader sourcestream = new streamreader(srcfilepath); byte[] filecontents = encoding.utf8.getbytes(sourcestream.readtoend()); sourcestream.close(); request.contentlength = filecontents.length; // send bytes server stream requeststream = request.getrequeststream(); requeststream.write(filecontents, 0, filecontents.length); requeststream.close(); ftpwebresponse response = (ftpwebresponse)request.getresponse(); debug.writeline("response status: {0} - {1}", response.statuscode, response.statusdescription); homecoming true; } private ftpwebrequest createftprequest(uri serveruri, string method) { ftpwebrequest request = (ftpwebrequest)webrequest.create(serveruri); request.enablessl = true; request.usepassive = true; request.usebinary = true; request.keepalive = true; request.credentials = new networkcredential(_username, _password); request.method = method; homecoming request; } private uri geturi(string remotefilepath) { homecoming new uri(_baseuri, remotefilepath); }
ok. figured out. .net 4.0 framework issue. build solution .net 3.5, worked beautifully.
hate see bugs in new releases of .net microsoft , wasting lot of quality time in figuring out.
c# ssl ftp
Comments
Post a Comment