Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6.1k views
in .NET FTP by (500 points)
I have been getting an exception when transferring large files to my FTP server lately. I'm not sure what is causing it at this point. Here is the log information:
DEBUG [FTPConnection] 2 Jun 2011 13:33:37.253 : Set LocalDirectory='C:\Data\'
DEBUG [FTPClient] 2 Jun 2011 13:33:37.253 : Connecting to 66.96.nnn.mmm:21
DEBUG [HostNameResolver] 2 Jun 2011 13:33:37.253 : Resolving 66.96.nnn.mmm
DEBUG [HostNameResolver] 2 Jun 2011 13:33:37.253 : 66.96.nnn.mmm resolved to 66.96.nnn.mmm
INFO [BaseSocket] 2 Jun 2011 13:33:37.253 : Connecting to 66.96.nnn.mmm:21 with timeout 30000 ms
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.347 : Setting socket timeout=30000
INFO [FTPControlSocket] 2 Jun 2011 13:33:37.347 : Command encoding=System.Text.SBCSCodePageEncoding
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.347 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.456 : 220-
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.753 : 220 Ipage FTP Server ready
DEBUG [FTPConnection] 2 Jun 2011 13:33:37.753 : Connected to 66.96.nnn.mmm (instance=2)
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.753 : ---> USER lwtrials
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.846 : 331 Password required for lwtrials
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:37.846 : ---> PASS ********
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.065 : 230 User lwtrials logged in
DEBUG [FTPConnection] 2 Jun 2011 13:33:38.065 : Successfully logged in
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.065 : ---> FEAT
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : 211-Features:
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : MDTM
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : MFMT
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : TVFS
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : MFF modify;UNIX.group;UNIX.mode;
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : SITE MKDIR
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : SITE RMDIR
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : SITE UTIME
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : SITE SYMLINK
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : REST STREAM
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.189 : SIZE
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.501 : 211 End
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.501 : ---> TYPE I
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.595 : 200 Type set to I
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.595 : ---> PWD
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.689 : 257 "/" is the current directory
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.689 : NewActiveDataSocket(0)
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:38.689 : ---> PORT 192,168,1,134,192,45
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:39.001 : 200 PORT command successful
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:39.001 : ---> STOR 002010VEACHA.zip
DEBUG [FTPControlSocket] 2 Jun 2011 13:33:39.203 : 150 Opening BINARY mode data connection for 002010VEACHA.zip
DEBUG [FTPActiveDataSocket] 2 Jun 2011 13:33:39.203 : AcceptConnection() succeeded
DEBUG [FTPClient] 2 Jun 2011 13:37:25.466 : Closing source stream
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : Caught exception
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : System.IO.IOException: Unable to write data to the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append, Boolean alwaysCloseStreams)
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : CAUSED BY - System.Net.Sockets.SocketException: Unable to write data to the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
ERROR [FTPClient] 2 Jun 2011 13:37:25.466 : at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : SystemException in Put(Stream,string,bool)
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : System.IO.IOException: Unable to write data to the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append, Boolean alwaysCloseStreams)
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : at EnterpriseDT.Net.Ftp.FTPClient.Put(Stream srcStream, String remoteFile, Boolean append)
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : CAUSED BY - System.Net.Sockets.SocketException: Unable to write data to the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
ERROR [FTPClient] 2 Jun 2011 13:37:25.560 : at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
DEBUG [FTPControlSocket] 2 Jun 2011 13:37:25.575 : Setting socket timeout=500
ERROR [FTPControlSocket] 2 Jun 2011 13:37:26.605 : Read failed ('' read so far)
WARN [FTPClient] 2 Jun 2011 13:37:26.605 : ReadReply failed
WARN [FTPClient] 2 Jun 2011 13:37:26.605 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
WARN [FTPClient] 2 Jun 2011 13:37:26.605 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadLine()
WARN [FTPClient] 2 Jun 2011 13:37:26.605 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadReply()
WARN [FTPClient] 2 Jun 2011 13:37:26.605 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransfer()
ERROR [FTPClient] 2 Jun 2011 13:37:26.605 : Exception in ValidateTransferOnError())
ERROR [FTPClient] 2 Jun 2011 13:37:26.605 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 2 Jun 2011 13:37:26.605 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransfer()
ERROR [FTPClient] 2 Jun 2011 13:37:26.605 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransferOnError()
DEBUG [FTPControlSocket] 2 Jun 2011 13:37:26.605 : Setting socket timeout=30000
DEBUG [FTPConnection] 2 Jun 2011 13:37:26.605 : GetLastWriteTime(002010VEACHA.zip)
WARN [FTPConnection] 2 Jun 2011 13:37:26.621 : Could not retrieve mod

6 Answers

0 votes
by (162k points)
It certainly looks like a server timeout. The other possibility is a firewall timeout - the firewall then kills the connection.
0 votes
by (500 points)
So is there any way to handle a problem like this? Do you have any example code that deals with this kind of situation? Would using the FTPconnectionClosedException class be the way to handle this problem?

I would guess that if this problem occurs, the software should be able to detect it and then reconnect and resume sending the file. Does that sound like the right way to proceed? If so, is there example code that demonstrates this?

Again, any help and especially example code, would be appreciated.
0 votes
by (500 points)
OK, I went ahead and modified my code as follows. Does this seem like the correct way of dealing with this problem?
      /// <summary>
      /// Event handler that is called when the send button is clicked. This
      /// method starts the <br/>FTP transfer asynchronously and then returns.
      /// </summary>
      /// <param name="sender">Object that raised the event.</param>
      /// <param name="e">Event arguments.</param>
      void SendClick(object sender, RoutedEventArgs e)
      {
         // create a background worker thread and set its parameters
         bgWorker = new BackgroundWorker();
         bgWorker.WorkerReportsProgress = true;
         bgWorker.WorkerSupportsCancellation = false;
         bgWorker.DoWork += DoWork;
         bgWorker.ProgressChanged += ProgressChanged;
         bgWorker.RunWorkerCompleted += WorkerComplete;
         
         SetStatus("Transferring data to the server...");
         
         // start the background worker thread
         bgWorker.RunWorkerAsync();
      }
      
      /// <summary>
      /// Background worker main function. It handles the FTP transfers
      /// and reports progress as the transfer progresses.
      /// </summary> 
      /// <param name="sender">The background worker thread.</param>
      /// <param name="e">The dowork event parameters.</param>
      private void DoWork(object sender, DoWorkEventArgs e)
      {
         FTPConnection      ftp;
         string            zipFile;
         FileStream         stream;
         BackgroundWorker   worker = sender as BackgroundWorker;
         bool            uploadSucceded = true;
         
         xferStatus = TransferStatus.Succeeded;
         ftpErrMsg = "";
         ftp = new FTPConnection();
         ftp.LocalDirectory = DIRECTORY;
         // set log information
         FTPConnection.LogFile = FTP_LOG_NAME;
         FTPConnection.LogLevel = LogLevel.All;
         // set all of the FTP parameters
         ftp.ServerAddress = "66.96.xxx.yyy"; // hide real server address
         ftp.UserName = "lwtrials";
         ftp.Password = "*******"; // hide real password
         ftp.ConnectMode = FTPConnectMode.ACTIVE;
         ftp.TransferType = FTPTransferType.BINARY;
         ftp.AutoLogin = true;
         ftp.Timeout = 30000;
         ftp.UseGuiThreadIfAvailable = false;
         // connect to the server
         try {
            ftp.Connect();
         } catch (Exception ex) {
            xferStatus = TransferStatus.NoConnect;
            ftpErrMsg = ex.Message;
         }
         for (int i = (numberPatients - 1); i >= 0; i--) {
            if (ftp.IsConnected) {
               zipFile = string.Format("{0}.zip", patients[i]);
               worker.ReportProgress(0, string.Format("Transferring file {0}", zipFile));
               stream = File.OpenRead(zipFile);
               stream.Seek(0, SeekOrigin.Begin);
               try {
                  uploadSucceded = true;
                  ftp.UploadStream(stream, zipFile);
               } catch (System.IO.IOException) {
                  // this is usually caused by the server closing the
                  // connection so reconnect and resume the transfer
                  try {
                     ftp.Close();
                     ftp.Connect();
                     ftp.ResumeTransfer();
                     ftp.UploadStream(stream, zipFile, true);
                  } catch (Exception) {
                     uploadSucceded = false;
                     xferStatus = TransferStatus.UploadFail;
                     ftpErrMsg = ex.Message;
                     TRACE("FTP resume exception : " + ftpErrMsg, 1);
                  }
               } catch (Exception ex) {
                  // if we have an exception, then the upload failed
                  uploadSucceded = false;
                  xferStatus = TransferStatus.UploadFail;
                  ftpErrMsg = ex.Message;
                  TRACE("FTP upload exception : " + ftpErrMsg
0 votes
by (162k points)
Yes, looks good.
0 votes
by (220 points)
Query1
Why is it that you call the .UploadStream() after the .ResumeTransfer()?
Isn't it not needed?

Query2
Is this still necessary if all of the bytes have been transferred?
My code seems to fail despite every byte having been uploaded already. (Mind you, it gives a EnterpriseDT.Net.Ftp.ControlChannelIOException)
0 votes
by (220 points)
Nevermind about Query 1 - I just looked at the docs again and noticed the "Makes the NEXT transfer" bit.

Nevermind about Query 2 - I found your other post that answers it.

Categories

...