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

New Post: SftpClient.UploadFile doesn't seem to be uploading anything

$
0
0
I have the following code. Everything seems to work fine. I can connect to the server and list directory files. However, when I perform the UploadFile(), nothing is uploaded to the server. It gets all the way tot he end without error, but nothing is uploaded. Any ideas?

Thanks,

Tim
     Console.WriteLine("Creating client and connecting");
        using (var client = new SftpClient(host, port, username, password))
        {
            client.Connect();
            Console.WriteLine("Connected to {0}", host);

            client.ChangeDirectory(workingdirectory);
            Console.WriteLine("Changed directory to {0}", workingdirectory);

            var listDirectory = client.ListDirectory(workingdirectory);
            Console.WriteLine("Listing directory:");
            foreach (var fi in listDirectory)
            {
                Console.WriteLine(" - " + fi.Name);
            }

            using (var fileStream = File.OpenRead(uploadfile))
            {
                Console.WriteLine("Uploading {0} ({1:N0} bytes)",
                                    uploadfile, fileStream.Length);
                client.BufferSize = 4 * 1024; // bypass Payload error large files
                client.UploadFile(fileStream, "TestFile.txt");
            }

            client.Disconnect();

            /*Console.WriteLine("Writing File");
            byte[] uploadData = File.ReadAllBytes(uploadfile);
            client.WriteAllBytes("Test.txt", uploadData);

            Console.WriteLine("Disconnecting");
            client.Disconnect();*/
        }

        Console.WriteLine("Press any key to exit...");
        Console.ReadLine();

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>