I'm trying to write a program that will automatically download the latest client files from from their FTP site. I can successfully access the site using an FTP client, but when I try to do so programmatically, I run into errors. I've tried multiple FTP clients and I can't get any of them to work.
For example, I use WinSCP to access the site, and it has this handy feature where it generates the code necessary to connect to the current site. Here's an example:
// Set up session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "ftp.site.com",
PortNumber = 21,
UserName = "username",
Password = "password",
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
}
I can copy that generated code verbatim, put it into a c# program, and I get the error
An attempt was made to access a socket in a way forbidden by its access permissions x.x.x.x:21
Is there something I'm doing wrong, or does the client have something configured on their FTP site that prevents what I'm trying to do?
After something changed on my end, I don't know exactly what, the errors went away and I can now successfully access the FTP site.