Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while uploading a file to directory #1713

Open
ebartlomiej89 opened this issue Jan 29, 2025 · 3 comments
Open

Error while uploading a file to directory #1713

ebartlomiej89 opened this issue Jan 29, 2025 · 3 comments

Comments

@ebartlomiej89
Copy link

Latest version on library throws exception:

2025-01-27 11:28:30.272 | FluentFTP.Exceptions.FtpException
FluentFTP.Exceptions.FtpException: Error while uploading the file to the server. See InnerException for more info. ---> System.TimeoutException: Timed out trying to read data from the socket stream!
w FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
w FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
w FluentFTP.Client.BaseClient.BaseFtpClient.FluentFTP.IInternalFtpClient.GetReplyInternal(String command, Boolean exhaustNoop, Int32 timeOut, Boolean useSema)
w FluentFTP.Client.BaseClient.BaseFtpClient.FluentFTP.IInternalFtpClient.ExecuteInternal(String command)
w FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart)
w FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart)
w FluentFTP.FtpClient.OpenWriteInternal(String path, FtpDataType type, Int64 fileLen, Boolean ignoreStaleData)
w FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action1 progress, FtpProgress metaProgress) --- Koniec śladu stosu wyjątków wewnętrznych --- w FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action1 progress, FtpProgress metaProgress)
w FluentFTP.FtpClient.UploadBytes(Byte[] fileData, String remotePath, FtpRemoteExists existsMode, Boolean createRemoteDir, Action1 progress) w RozsylaczDokumentow3.Classes.SendToFTP.<>c__DisplayClass0_2.<CheckConnection>b__1(Task1 n) w Z:\GIT\Rozsyłacz dokumentów\RozsylaczDokumentow18\Classes\SendToFTP.cs:wiersz 151System.TimeoutException: Timed out trying to read data from the socket stream!
w FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
w FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
w FluentFTP.Client.BaseClient.BaseFtpClient.FluentFTP.IInternalFtpClient.GetReplyInternal(String command, Boolean exhaustNoop, Int32 timeOut, Boolean useSema)
w FluentFTP.Client.BaseClient.BaseFtpClient.FluentFTP.IInternalFtpClient.ExecuteInternal(String command)
w FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart)
w FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart)
w FluentFTP.FtpClient.OpenWriteInternal(String path, FtpDataType type, Int64 fileLen, Boolean ignoreStaleData)
w FluentFTP.FtpClient.UploadFileInternal(Stream fileData, String localPath, String remotePath, Boolean createRemoteDir, FtpRemoteExists existsMode, Boolean fileExists, Boolean fileExistsKnown, Action`1 progress, FtpProgress metaProgress)

Please help me ;)

@FanDjango
Copy link
Collaborator

What are you doing? Source code?

What is happening? Verbose log?

This exception alone is not enough information.

@ebartlomiej89
Copy link
Author

ebartlomiej89 commented Feb 4, 2025

This error has occurs when i execute this code.

FtpConfig config = new FtpConfig();

if (passiveMode)
{
    config.DataConnectionType = FtpDataConnectionType.PASV;
}

FtpClient client = new FtpClient(Host, User, Password, Port, config);

try
{
    client.Config.ConnectTimeout = 20000;
    TaskScheduler ts = TaskScheduler.FromCurrentSynchronizationContext();
    client.CheckAsync().ContinueWith(n =>
    {
        if (n.Result == true)
        {
            try
            {
                client.SetWorkingDirectory(Katalog);

                byte[] bytes = new byte[4];

                bytes[0] = Convert.ToByte('T');
                bytes[1] = Convert.ToByte('E');
                bytes[2] = Convert.ToByte('S');
                bytes[3] = Convert.ToByte('T');

                client.UploadBytes(bytes, "test.txt");
                client.DeleteFile("test.txt");

                labelConnectionStatus.Text = " Udało się nawiązać połączenie z serwerem FTP.";
                labelConnectionStatus.ImageAlignToText = ImageAlignToText.LeftCenter;
                labelConnectionStatus.ImageOptions.Image = Properties.Resources.tick16;
                Progress.Hide();
                labelConnectionStatus.Show();
            }
            catch (Exception e)
            {
                Controller.Instance.Log.Error(e);
                labelConnectionStatus.Text = string.Format(" Nie udało się nawiązać połączenia z serwerem FTP.");
                labelConnectionStatus.ImageAlignToText = ImageAlignToText.LeftCenter;
                labelConnectionStatus.ImageOptions.Image = Properties.Resources.cross16;
                Progress.Hide();
                labelConnectionStatus.Show();

                string error = $"Nie udało się nawiązać połączenia z serwerem FTP z powodu:{Environment.NewLine}{e.ToString()}";
                if (!String.IsNullOrWhiteSpace(taskName))
                {
                    error = $"W trakcie sprawdzania połączenia FTP dla zadania {taskName} nie udało się nawiązać połączenia z serwerem FTP z powodu:{Environment.NewLine}{e.ToString()}";
                }

                Controller.Instance.Log.Error(error);
            }
        }
        else
        {
            labelConnectionStatus.Text = " Nie udało się nawiązać połączenia z serwerem FTP.";
            labelConnectionStatus.ImageAlignToText = ImageAlignToText.LeftCenter;
            labelConnectionStatus.ImageOptions.Image = Properties.Resources.cross16;
            Progress.Hide();
            labelConnectionStatus.Show();

            string error = $"Nie udało się nawiązać połączenia z serwerem FTP";
            if (!String.IsNullOrWhiteSpace(taskName))
            {
                error = $"W trakcie sprawdzania połączenia FTP dla zadania {taskName} nie udało się nawiązać połączenia z serwerem FTP";
            }

            Controller.Instance.Log.Error(error);
        }
    }, ts);
}
finally
{
    if (client.IsConnected)
        client.Disconnect();
}

The error is thrown when i run line:
client.UploadBytes(bytes, "test.txt");

Data for connection are ok. Connection was estabilished.

@FanDjango
Copy link
Collaborator

               client.SetWorkingDirectory(Katalog);

                byte[] bytes = new byte[4];

                bytes[0] = Convert.ToByte('T');
                bytes[1] = Convert.ToByte('E');
                bytes[2] = Convert.ToByte('S');
                bytes[3] = Convert.ToByte('T');

                client.UploadBytes(bytes, "test.txt");
                client.DeleteFile("test.txt");

I tried such code. It worked for me.

Please provide a log of what is happening to cause the timeout exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants