Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.7k views
in .NET FTP by (800 points)
I'm getting a strange error from using the FTPConnection object, and I'm not sure what's causing it. Below is the code that I'm using to attempt to upload a file, along with the error stack that I'm getting, and the FTP log information. Any advice would be greatly appreciated.

Code:
using( FTPConnection cnx = new FTPConnection() )
{
    this.setupConnection( cnx );

    #if DEBUG
    FTPConnection.LogFile = "Ftp.log";
    FTPConnection.LogLevel = EnterpriseDT.Util.Debug.LogLevel.Debug;
    #endif

    cnx.Connect();
    if( this.config.RequiresLogin )
    {
        cnx.Login();
    }
    cnx.BytesTransferred += new BytesTransferredHandler( FtpBytesTransferred );
    cnx.ChangeWorkingDirectory( this.config.FolderPath );
    cnx.UploadFile( filepath, filepath.Substring( filepath.LastIndexOf( "\\" ) + 1 ) );
    cnx.BytesTransferred -= new BytesTransferredHandler( FtpBytesTransferred );
}

private void setupConnection( FTPConnection cnx )
{
    cnx.ServerAddress = this.config.Host;
    cnx.UserName = this.config.Username;
    cnx.Password = this.config.Password;
    cnx.ConnectMode = this.config.ConnectMode;
    cnx.TransferType = FTPTransferType.BINARY;
}



Error stack:
System.IO.IOException: Failed to accept connection within timeout period (0)
at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append, Boolean alwaysCloseStreams)
at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPClient.Put(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPConnection.UploadFile(String localPath, String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPConnection.UploadFile(String localPath, String remoteFile)
at BackBurner.Service.FtpClient.UploadFile(String filepath) in C:\@ryexley\Visual Studio 2005\Projects\BackBurner\BackBurner.Service\FtpClient.cs:line 103
at BackBurner.Service.Backup.ExportToFTP() in C:\@ryexley\Visual Studio 2005\Projects\BackBurner\BackBurner.Service\Backup.cs:line 346

FTP log:
DEBUG [HostNameResolver] 8 Mar 2007 13:19:49.609 : vpctestserver resolved to xxx.xxx.xx.xx
DEBUG [FTPClient] 8 Mar 2007 13:19:49.609 : Connecting to xxx.xxx.xx.xx:21
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.625 : 220 Microsoft FTP Service
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.640 : ---> USER ryexley
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.640 : 331 Password required for ryexley.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.640 : ---> PASS ********
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.640 : 230 User ryexley logged in.
DEBUG [FTPConnection] 8 Mar 2007 13:19:49.640 : Successfully logged in
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.640 : ---> TYPE I
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.656 : 200 Type set to I.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.656 : ---> PWD
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.656 : 257 "/ryexley" is current directory.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.671 : ---> CWD /ryexley/Backup
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.671 : 250 CWD command successful.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.671 : ---> PWD
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.687 : 257 "/ryexley/Backup" is current directory.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.687 : NewActiveDataSocket(0)
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.703 : ---> PORT xxx,xxx,xx,xxx,xx,xxx
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.703 : 200 PORT command successful.
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.703 : ---> STOR BackBurner.200703081319.zip
DEBUG [FTPControlSocket] 8 Mar 2007 13:19:49.703 : 150 Opening BINARY mode data connection for BackBurner.200703081319.zip.
ERROR [FTPClient] 8 Mar 2007 13:19:49.718 : Caught exception : System.IO.IOException: Failed to accept connection within timeout period (0)
System.IO.IOException: Failed to accept connection within timeout period (0)
at EnterpriseDT.Net.StandardSocket.Accept(Int32 timeout)
at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.AcceptConnection()
at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.get_DataStream()
at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append, Boolean alwaysCloseStreams)


Any ideas what's wrong? Thanks.

2 Answers

0 votes
by (162k points)
You're in active mode, so the client is waiting for the server to initiate a connection. The server doesn't do so within the timeout period.

Probably a firewall somewhere is blocking the server's connection attempt.
0 votes
by (800 points)
OK, a little more weirdness to throw into the issue...

The *first* time I run the app (and attempt to upload) after the server is rebooted, it seems to work OK. Anytime after that first time, I get this error. If I reboot the server again, and try it again...once more, it works the first time, but not again after that unless I reboot the server. Is the server somehow maintaining the original open connection with the client somehow? That seems a little strange to me.

Also, the (windows) firewall on both the client and the server is turned off, so I'm guessing that's not the problem.

Categories

...