-1

Few weeks ago, I set a ftp server in aws windows. And when I tried to download files in ftp server using WebRequestMethods.Ftp.DownloadFile; , it didnt work. But when I tried to get file list from ftp server using WebRequestMethods.Ftp.ListDirectory, it did work! I tried to download files with passive mode, so I thought if there would be something wrong in passive mode, so I used filezilla to connect ftp server with passive mode. and it did work well. I could see file list and upload/download files in ftp server. so Im thinking passive mode is working well at least and it might not be the problem.

And this is the error message that I got when I try to download files from ftp server

System.Net.WebException: Server returned an error: 501 Invalid number of parameters.

It always is this message.

and this is the part of code that I wrote for ftp download connection.


FtpWebRequest requestFTPUploder = (FtpWebRequest)WebRequest.Create(FTP_Address);
requestFTPUploder.UsePassive = true;
requestFTPUploder.Method = WebRequestMethods.Ftp.DownloadFile;
requestFTPUploder.Credentials = new NetworkCredential(User_Name, Password);


The 'FTP_Address' is ip v4 address for connection. I didnt set DNS for my ftp server and it works well for getting list(WebrequestMethods.Ftp.ListDirectory) I added ':20' and ':21' for selection for specific port numbers. And it also worked well for getting file list. Please help. Ive been struggling for this for weeks.

**if i wrote something wrong, sorry for that. This is my first time to actually write something in stackoverflow. Ive always read other people's questions.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • I'd use a different ftp library for a start. FtpWebRequest is quite limited and there are certainly more features lobs out there - edFTP or WinSCP's wrapper for example. Whatever FWR is sending, the server doesn't like it. Obtain the exact command being sent and also give us the debug log from FileZilla so we can compare – Caius Jard Dec 24 '21 at 07:26
  • Ordinarily when a server will send directory lists (which travel over port 21) but won't send files (which travel over a port number chosen at random usually a lot higher up) it is because of fire walling. Using passive mode can help because it reverses the direction; in a normal case the server gives you a port and expects you to connect to it. That might be firewalled so passive turns it around and instructs the server to connect into you (normally you have more control over your firewall that you do over the server's firewall). Modern routers will see a PASV instruction and dynamically.. – Caius Jard Dec 24 '21 at 07:31
  • ..create a port forwarding so that the connection can work (and if your client has done something like PASV 192.168.3.12,12345 the router will adjust it to be yoir public IP and then use that info to create the port forward so that the connection from server to you will succeed) - this means that passive mode is generally more compatible with typical home or office NAT style networks even if they don't have a firewall per se – Caius Jard Dec 24 '21 at 07:34
  • All in, if FileZilla works and your code doesn't we need to see logs of what commands are being emitted by both so we can compare the difference - if you can't easily get logs out of FWR - see eg https://stackoverflow.com/questions/9664650/output-log-using-ftpwebrequest - then just switch to using another library that does more willingly give the logs; it might even make the problem go away – Caius Jard Dec 24 '21 at 07:38

1 Answers1

0

I guess requestUploder should be requestDownloader. Moreover WebRequest.Create() is deprecated.

But anyway, try to put a look into FTP_Address variable. It should be named with a name like FTP_url, so it should contain the URL of the file inside the ftp server (not only the ftp server address).

FtpWebRequest request =
    (FtpWebRequest)WebRequest.Create("ftp://ftp.server.com/folder1/folder2/file.zip");
GibbOne
  • 629
  • 6
  • 10
  • Hmmm like i said, I dont have a dns server address for my ftp server. But can I create URL without domain name without paying dns company to get dns server address? As far as i know, it isnt possible. Right? – DancingElephant Dec 24 '21 at 06:16