Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting with ftp ends in 501 error #44

Closed
bzuidgeest opened this issue Oct 1, 2018 · 6 comments
Closed

Connecting with ftp ends in 501 error #44

bzuidgeest opened this issue Oct 1, 2018 · 6 comments

Comments

@bzuidgeest
Copy link

Hello,

I'm trying to connect to an ftp server using ftpes. I checked with filezilla and the server does require explicit TLS ftp. When connecting I get an CheckCertificate and the valid property equals true. After that any command returns 501 ('Server cannot accept argument.'). Is there an easy way to see which command is causing this? At this moment I only have stack trace which is not very informative. It happens as soon as I hit HasFeature in code below.

The ftp server is the built in microft ftp server and output from FEAT is

Response: 211-Extended features supported:
Response: LANG EN*
Response: UTF8
Response: AUTH TLS;TLS-C;SSL;TLS-P;
Response: PBSZ
Response: PROT C;P;
Response: CCC
Response: HOST
Response: SIZE
Response: MDTM
Response: REST STREAM
Response: 211 END

Stacktrace:
at ArxOne.Ftp.FtpSession.ThrowException(FtpReply reply)
at ArxOne.Ftp.FtpSession.Expect(FtpReply reply, Int32[] codes)
at ArxOne.Ftp.FtpSession.OpenActiveDataStream(TimeSpan connectTimeout, TimeSpan readWriteTimeout)
at ArxOne.Ftp.FtpSession.OpenDataStream(Boolean passive, TimeSpan connectTimeout, TimeSpan readWriteTimeout, FtpTransferMode transferMode, Nullable1 streamMode) at ArxOne.Ftp.FtpClientUtility.OpenDataStream(FtpSession session, FtpTransferMode transferMode, FtpStreamMode streamMode) at ArxOne.Ftp.FtpClientUtility.ProcessList(FtpSession session, FtpPath path) at ArxOne.Ftp.FtpClient.Process[TResult](Func2 action, FtpSession session)
at ArxOne.Ftp.FtpClientUtility.ListEntries(FtpClient ftpClient, FtpPath path)
at NugetHelper.Program.Main(String[] args) in \Program.cs:line 36
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

using (var ftpClient = new FtpClient(new Uri("ftpes://ftp.*****"), new NetworkCredential("****", "******"), new FtpClientParameters() { Passive = false, })) { ftpClient.CheckCertificate += FtpClient_CheckCertificate; if (ftpClient.ServerFeatures.HasFeature("MLSD")) { var temp = ftpClient.MlsdEntries("/"); //.Mlsd(new FtpPath("/")); } }

@picrap
Copy link
Member

picrap commented Oct 1, 2018

Hi, there is an event named Request (and a lot of other events) in the FtpClient class. You can subscribe to them and see the issued commands.
Let me know if you need some help.

@bzuidgeest
Copy link
Author

Hello,

Wow, very fast reply. I used the events you suggested and got this

Reply:220 WARNING: Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is suspected.
Request:AUTH TLS
Reply:234 AUTH command ok. Expecting TLS Negotiation.
Request:USER ***
Reply:331 Password required
Request:PASS ****
Reply:230 Welcome to the FTP Server of ****, User logged in.
Request:FEAT
Reply:211 Extended features supported:, LANG EN
, UTF8, AUTH TLS;TLS-C;SSL;TLS-P;, PBSZ, PROT C;P;, CCC, HOST, SIZE, MDTM, REST STREAM, END
Request:PBSZ 0
Reply:200 PBSZ command successful.
Request:PROT P
Reply:200 PROT command successful.
Request:TYPE I
Reply:200 Type set to I.
Request:PORT 10,60,8,101,228,170
Reply:501 Server cannot accept argument.

I'm guessing here, but my current thinking is that this is a local network configuration issue. They changed the server and they might have forgotten some networking config in a firewall somewhere.
Thanks for the quick assist.

@picrap
Copy link
Member

picrap commented Oct 1, 2018

Apparently you are using active connections, which work only if your client has a public IP that the server can reach. Otherwise, you should stick to passive transfers (FtpClientParameters.Passive=true).

@bzuidgeest
Copy link
Author

bzuidgeest commented Oct 1, 2018

You are right, I recheck previous code and the server requires passive to be true. I must have changed that while testing. unfortunately it just gives me another error:

Reply:220 WARNING: Unauthorized access to this system is forbidden and will be prosecuted by law. By accessing this system, you agree that your actions may be monitored if unauthorized usage is suspected.
Request:AUTH TLS
Reply:234 AUTH command ok. Expecting TLS Negotiation.
Request:USER ***
Reply:331 Password required
Request:PASS ****
Reply:230 Welcome to the FTP Server of IT-Workz, User logged in.
Request:FEAT
Reply:211 Extended features supported:, LANG EN*, UTF8, AUTH TLS;TLS-C;SSL;TLS-P;, PBSZ, PROT C;P;, CCC, HOST, SIZE, MDTM, REST STREAM, END
Request:PBSZ 0
Reply:200 PBSZ command successful.
Request:PROT P
Reply:200 PROT command successful.
Request:TYPE I
Reply:200 Type set to I.
Request:PASV
Reply:227 Entering Passive Mode (,,127,18,19,160).
Exception thrown: 'ArxOne.Ftp.Exceptions.FtpTransportException
Socket error to ..127.18

I can reach the server from local desktop, but I'm debugging on a remote server. On the remote server also cannot connect using filezilla. Should have tested that first :(. So must be a local network problem. Thanks again for the support.

p.s. It worked before and only started to malfunction after server upgrade to use TLS, the admins over here must have made a mistake.

@picrap
Copy link
Member

picrap commented Oct 1, 2018

Not sure it's their fault, unfortunately. We had trouble with FileZilla server and I never really understood why. If you have time for tests and fix, you are welcome :)

@picrap picrap reopened this Oct 1, 2018
@bzuidgeest
Copy link
Author

Sorry, must be a translation error. We are mostly doing development work on remote desktops/machines (rdp) over here. So server and client lines get blurred somewhere sometimes. I was referring to testing with the filezilla client on local and on a remote machine, and then connecting to the same Microsoft ftp server. We are not using FileZilla server so I cannot help diagnose that. I have now verified that the code works on local but not remote clients. That means fire walling somewhere. So you are not saving our network guys :) from work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants