NFe.Components.FTP.DoUpload C# (CSharp) Method

DoUpload() public method

Upload the file, to be used in a loop until file is completely uploaded
public DoUpload ( ) : long
return long
        public long DoUpload()
        {
            Byte[] bytes = new Byte[512];
            long bytes_got;
            bool a1 = false;
            bool a2 = false;

            try
            {
                bytes_got = file.Read(bytes, 0, bytes.Length);
                bytes_total += bytes_got;
                data_sock.Send(bytes, (int)bytes_got, 0);

                if (bytes_got <= 0)
                {
                    // the upload is complete or an error occured
                    file.Close();
                    file = null;

                    CloseDataSocket(); a1 = true;
                    ReadResponse(); a2 = true;
                    switch (response)
                    {
                        case 226:
                        case 250:
                            break;
                        default:
                            throw new Exception(responseStr);
                    }
                    SetBinaryMode(false);
                }
            }
            catch (Exception ex)
            {
                if (file != null)
                    file.Close();
                file = null;
                try
                {
                    if (!a1) CloseDataSocket();
                    if (!a2) ReadResponse();
                    SetBinaryMode(false);
                }
                catch { }
                throw ex;
            }
            return bytes_got;
        }