Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Problem with uploading to Unix

$
0
0
When I try to use SCPClient to copy several big files (1 gb) from windows machine to unix machine, I have problem
First target file have same size , but others don't uppload full. They have less size then source files.
It's code
using (var sftp = new SftpClient(Host, Port, Login, Password))
        {
            List<string> movedFiles = new List<string>();
            try
            {

                string[] SourceFiles = Directory.GetFiles(SourceDirectory, this.SourceFileName + this.SourceFileFormat);
                {
                    foreach (string sourceFile in SourceFiles)
                    {
                        string resultTargetFile = TargetName;
                        if (String.IsNullOrEmpty(TargetFileName) || isMask)
                        {
                            resultTargetFile = Path.Combine(TargetDirectory, Path.GetFileName(sourceFile)).Replace(@"\", "/");
                        }
                        movedFiles.Add(resultTargetFile);
                        sftp.Connect();
                        using (var streamFile = File.OpenRead(sourceFile))
                        {
                            sftp.UploadFile(streamFile, resultTargetFile);
                        }
                        sftp.Disconnect();
                        cntOperation++;
                    }
                }

            }

            catch (ThreadAbortException)
            {
                if (sftp.IsConnected)
                {
                    foreach (string _movedFile in movedFiles)
                    {
                        if (sftp.Exists(_movedFile))
                            sftp.Delete(_movedFile);
                    }

                    sftp.Disconnect();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteMessage(MessageType.Error, ex.ToString());
            }
        }

Viewing all articles
Browse latest Browse all 1729

Trending Articles