Login  
Search All Forums
Dart Home | PowerTCP FTP for .NET | Custom Development Reply | PowerTCP FTP for .NET Topics | Forums   
AuthorForum: PowerTCP FTP for .NET
Topic: ftp.Close()
mmorvant

From: Dallas, TX USA
Posts: 3
Member Since: 08/04/06
posted October 19, 2016 11:17 AM

This question does deal with an older assembly (4.5). It has been working flawlessly for all of our customers for quite some time. Last week a single client installation began to fail. I looked over the release notes past 4.5 and don't see anything that appears to be directly related. Here is the code in question.

public void TransferPackage(FtpSettings settings, string fullFileName, string destinationPath)
{
var fi = _Fs.FileInfo(fullFileName);
ManageForFtp(settings, c => {
c.Put(fullFileName, fi.Name, Synchronize.Off);
using (var ms = new MemoryStream())
using (var tw = new StreamWriter(ms))
{
c.Put(ms, fi.Name + ".req", 0, StoreType.Replace);
}
}, destinationPath);
}


private void ManageForFtp(FtpSettings settings, Action<Ftp> activity, string destinationPath)
{
if (settings == null) throw new ArgumentNullException("settings");
if (activity == null) throw new ArgumentNullException("activity");

var s = new FtpSession { Username = settings.Username, Password = settings.Password };
s.RemoteEndPoint.HostNameOrAddress = settings.Server.Host;
s.RemoteEndPoint.Port = settings.Server.Port > 0 ? settings.Server.Port : Ftp.DefaultPort;
if (settings.IsPassive) s.ConnectType = DataConnectType.Passive;

if (_Config.FtpProxy != null && !string.IsNullOrEmpty(_Config.FtpProxy.Host))
{
s.Proxy.Type = GetProxyType(_Config.FtpProxy.Kind);
s.Proxy.RemoteEndPoint.HostNameOrAddress = _Config.FtpProxy.Host;
s.Proxy.RemoteEndPoint.Port = _Config.FtpProxy.Port > 0 ? _Config.FtpProxy.Port : 88;
}

using (var _ftp = new Ftp { Session = s })
{
try
{
_ftp.Connect();
_ftp.Authenticate();

if (!string.IsNullOrEmpty(destinationPath)) _ftp.SetDirectory(destinationPath);

activity(_ftp);
}
catch { throw; }
finally
{
if (_ftp != null && _ftp.Connected)
_ftp.Close();
}
}
}

For brevity, we can assume that all of the configuration settings are correct. The behavior noted is as follows.

_Transfer.TransferPackage(<ftpSettings>, <accessibleFile>, "Inbox");
_LogInfo.WithMessage("Log message indicating successful Transfer");
File.Delete(<accessibleFile>);

When the following executes both the file and file + ".req" are properly transferred to the server (IpSwitch FTP). The connection is closed. However, the log message fails to fire. No exception is thrown. The lack of exception lead me to examine the "finally" clause. When that clause is commented out the application works as expected. I have moved the statements around outside of the "finally" clause and still get no exception being thrown. I had modified the "catch" clause in a few different patterns and none were successful in capturing any type of exception. The FTP server logs the connection being closed as successful and unremarkable. As expected without the "Close" statements connections are held open until the FTP server clears them out for being inactive.

Has anyone else had any issues with Close()?

Any help is appreciated!

Matthew
Jamie Powell (Admin)

From: Rome, NY USA
Posts: 380
Member Since: 03/13/07

Extra Support Options
Custom Application Development

posted October 20, 2016 4:39 PM

Thank you for your post.

If this only occurs against one server, it suggests that the server is incorrectly not closing the control connection after receiving the QUIT command when Ftp.Close() is called (per RFC959 section 4.1.1) (Ftp.Close() waits for the control connection to be closed before returning). For out-of-spec servers, you could use Ftp.Abort() instead.

------
-Non-current subscribers must contact sales@dart.com to update subscription and receive continued support as needed.
------

mmorvant

From: Dallas, TX USA
Posts: 3
Member Since: 08/04/06
posted October 25, 2016 6:09 AM

For clarification, all of our customers access the *same* central FTP server. Only one client has this issue. All others connect and close appropriately.
Jamie Powell (Admin)

From: Rome, NY USA
Posts: 380
Member Since: 03/13/07

Extra Support Options
Custom Application Development

posted October 27, 2016 5:05 PM

This behavior would suggest there is an issue with the specific client's machine/network/etc.

If you require further technical assistance for this issue please email jamie.powell@dart.com for information on purchasing a Subscription.

All the best,
Jamie
Reply | PowerTCP FTP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX