.net - FtpWebRequest/FtpWebResponse : connection is successful even if a bad password is provided after a successful connection -


i'm testing ftp connection user/password provided user.

everything work fine if run unit tests independently. if try ordered test, running ftp_test_sucessful before ftp_test_unsuccessful, ftp_test_unsuccessful test fail : ftp connection successful if provide bad password after successful connection.

passed          unit test   ftp_test_unsuccessful       00:00:02.3566157 passed          unit test   ftp_test_sucessful          00:00:00.3048244 failed          unit test   ftp_test_unsuccessful       00:00:00.2696941 not executed    unit test   ftp_test_sucessful          00:00:00 

how "reset" ftp connection ftp_test_unsuccessful test connection correctly.

here's unit tests :

'''<summary> '''basic unsuccessful ftp test '''</summary> <testmethod()> public sub ftp_test_unsuccessful()     _testsettings.ftpenabled = true     _testsettings.changeftpcredentials("user", "badpasword")     try         assert.isfalse(_testsettings.testftpsettings())      catch ex assertfailedexception         throw       catch ex net.webexception         dim ftpresponse ftpwebresponse = directcast(ex.response, ftpwebresponse)         assert.areequal(ftpstatuscode.notloggedin, ftpresponse.statuscode)      catch ex exception         assert.fail()     end try end sub  '''<summary> '''basic sucessful ftp test '''</summary> <testmethod()> public sub ftp_test_sucessful()     _testsettings.ftpenabled = true     _testsettings.changeftpcredentials("user", "goodpasword")     assert.istrue(_testsettings.testftpsettings()) end sub 

and here relevant code :

public function testftpsettings() boolean     dim ftpconnectiontestedsuccessfully boolean = false     dim response ftpwebresponse = gettestftpresponse()     dim statuscode system.net.ftpstatuscode = response.statuscode     response.close()     ftpconnectiontestedsuccessfully = (statuscode = net.ftpstatuscode.openingdata)      return ftpconnectiontestedsuccessfully end function  private function gettestftpresponse() ftpwebresponse     dim request ftpwebrequest = getftpconnection(webrequestmethods.ftp.listdirectory)     dim response ftpwebresponse = getftpresponse(request)      return (response) end function  private function getftpconnection(method string) ftpwebrequest     'get object used communicate server.      dim ftpadress uri = new uri(string.format("ftp://{0}:{1}", _                                                  me.ftpservername, _                                                  me.ftpport))      dim request ftpwebrequest = directcast(webrequest.create(ftpadress),  _                                               ftpwebrequest)      request.method = method     request.credentials = new networkcredential(me.ftpusername,                                                 me.getdecryptedpassword)     return request end function  public function getftpresponse(request ftpwebrequest) ftpwebresponse     return directcast(request.getresponse(), ftpwebresponse) end function 

thanks answer on how reuse ftpwebrequest connection , added request.keepalive = false getftpconnection function. , tests passed.

private function getftpconnection(method string) ftpwebrequest     'get object used communicate server.      dim ftpadress uri = new uri(string.format("ftp://{0}:{1}", _                                                  me.ftpservername, _                                                  me.ftpport))      dim request ftpwebrequest = directcast(webrequest.create(ftpadress),  _                                               ftpwebrequest)      request.method = method     request.keepalive = false     request.credentials = new networkcredential(me.ftpusername,                                                 me.getdecryptedpassword)     return request end function 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -