Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
4.4k views
in .NET FTP by (460 points)
One of the FTP sites I need to access prompts for a second User and pass after you submit the first prompt. Can the login to such a site be automated? We are using edtFTPnetPRO.dll v 4.2

8 Answers

0 votes
by (162k points)
You could do something like this:

ftp.AutoLogin = false;
ftp.Connect();
ftp.SendUserName("user1");
ftp.SendPassword("pwd1");
ftp.SendUserName("user2");
ftp.SendPassword("pwd2");


You need however a way to detect if the second username/pwd is required - does the server return a reply code that indicates this?[/list]
0 votes
by (460 points)
Here is the error I get when I tryed your suggestion:
The FTP client has already been connected to the server. The requested action must be performed before a connection is established.

Here is the error I get when I try to Login in the standard way:
EnterpriseDT.Net.Ftp.FTPException was caught
Message="narnia FTP server (Version wu-2.6.2+Sun) ready. (code=220)"
Source="edtFTPnetPRO"
StackTrace:
at EnterpriseDT.Net.Ftp.FTPControlSocket.ValidateReply(FTPReply reply, String[] expectedReplyCodes)
at EnterpriseDT.Net.Ftp.FTPClient.Password(String password)
at EnterpriseDT.Net.Ftp.FTPConnection.PerformAutoLogin()
at EnterpriseDT.Net.Ftp.SecureFTPConnection.Connect()
0 votes
by (162k points)
Could you post the log file of you trying to log in? That should give us enough info to figure out a solution.
0 votes
by (460 points)
pseudo code:

objFTP.ServerAddress = "***.***.***.***"
objFTP.ServerPort = 21
objFTP.UserName = "***********"
objFTP.Password = "***********"
objFTP.Connect()


Log File:

INFO [LicenseProperties] 28 Sep 2007 09:18:32.521 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 28 Sep 2007 09:18:32.531 : Production license
INFO [LicenseProperties] 28 Sep 2007 09:18:32.531 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 28 Sep 2007 09:18:32.531 : Production license
DEBUG [SSLFTPClient] 28 Sep 2007 09:18:32.531 : Connecting to ***.***.***.***:21
DEBUG [HostNameResolver] 28 Sep 2007 09:18:32.601 : ***.***.***.*** resolved to ***.***.***.***
DEBUG [SSLFTPControlSocket] 28 Sep 2007 09:18:32.621 : waitOnShutdownSSL=True
DEBUG [ExFTPControlSocket] 28 Sep 2007 09:18:32.671 : Connecting directly to ftp-server ***.***.***.***:21
DEBUG [ExFTPControlSocket] 28 Sep 2007 09:18:32.862 : Created control-socket: SocksContext=, ProxySettings=NoProxy, RemoteHost=***.***.***.***, controlPort=21, timeout=120000
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.862 : 220-FTP authentication :
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.872 : 220
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.872 : ---> USER *************
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.962 : 331-Password:
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.962 : 331
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:32.962 : ---> PASS ********
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:33.192 : 220 narnia FTP server (Version wu-2.6.2+Sun) ready.
INFO [FTPControlSocket] 28 Sep 2007 09:18:33.192 : Expected reply codes = [230,202]
DEBUG [AsyncProcessor] 28 Sep 2007 09:18:33.202 : Stopping FTP task processor.
DEBUG [AsyncProcessor] 28 Sep 2007 09:18:33.202 : FTP task processor stopped.
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:33.202 : ---> QUIT
DEBUG [FTPControlSocket] 28 Sep 2007 09:18:33.262 : 221 Goodbye.
DEBUG [SecureSocket] 28 Sep 2007 09:18:33.272 : Shutdown(Both)
ALL [FTPConnection] 28 Sep 2007 09:18:33.282 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler -> TestingApp.Form1.ftpconnection_Connected
ALL [FTPConnection] 28 Sep 2007 09:18:33.282 : Finding MainWindowHandle
ALL [FTPConnection] 28 Sep 2007 09:18:33.302 : MainWindowHandle found
ALL [FTPConnection] 28 Sep 2007 09:18:33.302 : Have GUI control
ALL [FTPConnection] 28 Sep 2007 09:18:33.302 : GUI control invocation not required
ALL [FTPConnection] 28 Sep 2007 09:18:33.302 : Invoking delegate dynamically
ALL [FTPConnection] 28 Sep 2007 09:18:34.514 : Dynamic delegate invocation complete
ALL [FTPConnection] 28 Sep 2007 09:18:34.514 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler -> TestingApp.Form1.ftpconnection_Connected
ALL [FTPConnection] 28 Sep 2007 09:18:34.514 : Have GUI control
ALL [FTPConnection] 28 Sep 2007 09:18:34.514 : GUI control invocation not required
ALL [FTPConnection] 28 Sep 2007 09:18:34.514 : Invoking delegate dynamically
ALL [FTPConnection] 28 Sep 2007 09:18:34.524 : Dynamic delegate invocation complete


This is the log when AutoConnect is set to "False"

objFTP.Connect()INFO [LicenseProperties] 28 Sep 2007 09:34:26.533 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 28 Sep 2007 09:34:26.533 : Production license
INFO [LicenseProperties] 28 Sep 2007 09:34:26.533 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 28 Sep 2007 09:34:26.533 : Production license
DEBUG [SSLFTPClient] 28 Sep 2007 09:34:26.533 : Connecting to ***.***.***.***:21
DEBUG [HostNameResolver] 28 Sep 2007 09:34:26.543 : ***.***.***.*** resolved to ***.***.***.***
DEBUG [SSLFTPControlSocket] 28 Sep 2007 09:34:26.543 : waitOnShutdownSSL=True
DEBUG [ExFTPControlSocket] 28 Sep 2007 09:34:26.553 : Connecting directly to ftp-server ***.***.***.***:21
DEBUG [ExFTPControlSocket] 28 Sep 2007 09:34:26.573 : Created control-socket: SocksContext=, ProxySettings=NoProxy, RemoteHost=***.***.***.***, controlPort=21, timeout=120000
DEBUG [FTPControlSocket] 28 Sep 2007 09:34:26.783 : 220-FTP authentication :
DEBUG [FTPControlSocket] 28 Sep 2007 09:34:26.793 : 220
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler -> TestingApp.Form1.ftpconnection_Connected
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : Finding MainWindowHandle
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : MainWindowHandle found
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : Have GUI control
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : GUI control invocation not required
ALL [FTPConnection] 28 Sep 2007 09:34:26.803 : Invoking delegate dynamically
ALL [FTPConnection] 28 Sep 2007 09:34:26.934 : Dynamic delegate invocation complete
DEBUG [EnterpriseDT.Net.Ftp.ExFTPConnection] 28 Sep 2007 09:34:28.476 : Starting KeepAlive thread with period 30s
0 votes
by (460 points)
This was for the same site; I hope this gives some clue to the solution of automating this type of connection

C:\>ftp -n SomeFTPServer.com
Connected to SomeFTPServer.com
220-FTP authentication :
220
ftp> User FirstUserName
331-Password:
331
Password:
220 narnia FTP server (Version wu-2.6.2+Sun) ready.
ftp> User SecUserName
331 Password required for SecUserName
Password:
230 User SecUserName logged in.  Access restrictions apply.
ftp> quit
221-You have transferred 0 bytes in 0 files.

C:\>
0 votes
by (460 points)
Here is what I came up with to get a successful login.
I set up an event handler on the ReplyReceived event and pass that back as strReply. This is needed because the FTPConnection object throws an exception,
0 votes
by (51.6k points)
No, but you can use the InvokeFTPCommand method as follows to achieve the same outcome:
objParamiters.objFTP.InvokeFTPCommand("PASS FirstPass", "220")


The first argument is the command that is sent to the server and the second is the expected reply code.

- Hans (EnterpriseDT)
0 votes
by (460 points)
Thanks Mike

Categories

...