the speed of uploading is very slow using C# assembly

Advertisement

Vanchy
Joined:
Posts:
1

the speed of uploading is very slow using C# assembly

I am trying to develop a automatic FTP program.
But I found that the speed of uploading a file is very slow. (compared to FtpWebRequest and FtpWebResponse)
I have set the "Sendbuf" to 0, but it doesn't work for me.
My 'TEST' file is only 72kb and it takes about 5 seconds to finish a file.
I have tried another FTP Server and got same problem.

Is there any transferOptions I have to set?

public SessionOptions FTP_Connect(int idx)
{
    string IP = Data_Class.FTP_List[idx].IP;
    string UserName = Data_Class.FTP_List[idx].User_name;
    string PassWord = Data_Class.FTP_List[idx].Password;
    string Port = Data_Class.FTP_List[idx].Port;
    string HostKey = "";

    sessionOptions = new SessionOptions
    {
        HostName = IP,
        UserName = UserName,
        Password = PassWord
    };

    if (Port == "22")
    {
        sessionOptions.Protocol = Protocol.Sftp;
        sessionOptions.SshHostKeyFingerprint = HostKey;
    }
    else
    {
        sessionOptions.Protocol = Protocol.Ftp;
        sessionOptions.FtpSecure = FtpSecure.Explicit;
    }

    sessionOptions.AddRawSettings("SendBuf", "0");

    return sessionOptions;
}

public string FTP_Upload(int idx, string LocalPath, string ServerPath, string FileName)
{
    try
    {
        sessionOptions = FTP_Connect(idx);
        DateTime StartTime = DateTime.Now;

        using (Session session = new Session())
        {
            session.Open(sessionOptions);
            session.DebugLogPath = "D:\\123.txt";

            TransferOptions transferOptions = new TransferOptions();
            transferOptions.TransferMode = TransferMode.Automatic;

            TransferOperationResult transferResult;
            transferResult = session.PutFiles(LocalPath, ServerPath, false, transferOptions);

            transferResult.Check();

            foreach (TransferEventArgs args in transferResult.Transfers)
            {
                if (args.Error == null)
                {
                    TimeSpan SecDuration = DateTime.Now - StartTime;
                    return string.Concat("Y/", "Upload ", FileName, " Takes:", SecDuration.TotalSeconds, "s");
                }
                else
                {
                    return string.Concat("NG1/", args.Error);
                }
            }
        };
        
        return string.Concat("NG2/", "Upload Fail");
    }
    catch (Exception ex)
    {
        return string.Concat("NG3/", ex.Message);
    }
    
}
  • log.txt (19.04 KB, Private file)

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum