I'm having trouble connect to the FTP server with my Dot Net Core 2 application it always times out funny thing is that I only experience the timing out issue when I deploy the Web API to the server on Absolute Hosting. When i connect to the FTP server via Filezilla it works fine, when i run the Web API locally on my machine and connect to the FTP server it works fine. Fixes I've tried: I removed the upload file size,increased the timeout interval,passed the SSL config setting.It still fails to connect when it is deployed to the server.
To connect to the FTP server in the Web API I'm using the FluentFTP nuget package.In the code i login to FTP server,Create a directory in the "wwwroot" folder, then upload file.Is there anything you can do on your side that can help.
My code is as follows:
Code: Select all
FtpClient client;
try
{
client = new FtpClient(clientIP)
{
Port = 11000,
Credentials = new NetworkCredential(Username, Password)
};
client.Connect(); //Times out on this line
}
catch ( Exception e)
{
Console.WriteLine(e);
return (StatusCode(500, new { error = e.StackTrace, message = "Failed to create FTP Client" }));
}
try
{
foreach (var activityFile in activity.Files.ToList())
{
if (activityFile.Length <= 0)
{
continue;
}
using (var ms = new MemoryStream())
{
activityFile.CopyTo(ms);
var fileBytes = ms.ToArray();
string yearFolder = todaysDate.Year.ToString();
string monthFolder = todaysDate.Month.ToString();
var directory = path + yearFolder + "/" + monthFolder + "/";
if (!(await client.DirectoryExistsAsync(directory)))
{
await client.CreateDirectoryAsync(directory);
}