0

When using WebClient I can specify a URL as the address when connecting to an FTP server, but when specifying an IP address it throws a FormatException inside mscorlib. Basically, to demonstrate:

using (WebClient client = new WebClient())
{
    client.UploadFile("ftp://localhost/test.dat", "STOR", "test.dat"); // No exception
    client.UploadFile("ftp://127.0.0.1/test.dat", "STOR", "test.dat"); // FormatException
}

The exception detail says "Input string was not in a correct format" and claims to be coming from System.Number.StringToNumber

I have tried it with and without the ":21" port number, but it makes no difference.

How can I use an IP Address with the WebClient class to upload a file to an FTP server?

user3690202
  • 3,844
  • 3
  • 22
  • 36
  • I cannot reproduce the problem. It works for me with `127.0.0.1`. Show us a full exception call stack (including an inner exception callstack) and [`WebClient` log file](https://stackoverflow.com/q/9664650/850848). – Martin Prikryl Jun 06 '17 at 06:22

1 Answers1

0

The issue was with the FTP server being used. Smallftpd returns non-compliant responses which fail to be parsed by WebClient, resulting in obscure number conversion errors. The answer was to switch to a different server software.

user3690202
  • 3,844
  • 3
  • 22
  • 36