<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FTP and SFTP - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/ftp-and-sftp/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Wed, 15 Nov 2023 03:10:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>FTP and SFTP - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Track Progress of SFTP File Upload/Download in C#.NET</title>
		<link>https://thecodebuzz.com/how-to-show-track-progress-bar-sftp-file-download-upload-csharp-net/</link>
					<comments>https://thecodebuzz.com/how-to-show-track-progress-bar-sftp-file-download-upload-csharp-net/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 24 Jun 2023 20:12:05 +0000</pubDate>
				<category><![CDATA[FTP and SFTP]]></category>
		<category><![CDATA[Track Progress of SFTP File Upload/Download in C#.NET]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=27719</guid>

					<description><![CDATA[<p>How to Track Progress of SFTP File Upload/Download in C#.NET Today in this article, we will see how to track progress of SFTP operation using C#.NET code. We can easily display the progress of file upload or download in a progress bar with SSH.NET library-supported methods required for the SFTP operations. We will explore this [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/how-to-show-track-progress-bar-sftp-file-download-upload-csharp-net/">How to Track Progress of SFTP File Upload/Download in C#.NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading" id="aioseo-ftp---file-download-and-upload-using-c-net">How to Track Progress of SFTP File Upload/Download in C#.NET</h1>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/ftp-file-download-upload-using-csharp-net-core/" target="_blank" rel="noreferrer noopener"><img fetchpriority="high" decoding="async" width="1024" height="333" src="https://www.thecodebuzz.com/wp-content/uploads/2023/06/displaying-progress-file-upload-in-a-progressbar-with-ssh-net-1024x333.jpg" alt="Track Progress of SFTP " class="wp-image-27749" srcset="https://thecodebuzz.com/wp-content/uploads/2023/06/displaying-progress-file-upload-in-a-progressbar-with-ssh-net-1024x333.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/06/displaying-progress-file-upload-in-a-progressbar-with-ssh-net-300x98.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/06/displaying-progress-file-upload-in-a-progressbar-with-ssh-net-768x250.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/06/displaying-progress-file-upload-in-a-progressbar-with-ssh-net-785x255.jpg 785w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Today in this article, we will see how to track progress of SFTP operation using C#.NET code.</p>



<p></p>



<p>We can easily display the progress of file upload or download in a progress bar with SSH.NET library-supported methods required for the SFTP operations.</p>



<p></p>



<p>We will explore this option using the <strong>SSH.NET</strong> library for .NET/.NET Core.</p>



<p></p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-getting-started">Getting Started</a></li><li><a href="#aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using SFTPClient</a></li><li><a href="#aioseo-how-to-chnage-default-file-path-in-sftp">Adding Progress bar &#8211; UploadFile SFTP operations</a><ul><li><a href="#aioseo-define-a-callback-method">Define a callback method</a></li></ul></li><li><a href="#aioseo-tracking-progress-sftp-upload-file">Tracking Progress &#8211; SFTP Upload file</a></li><li><a href="#aioseo-adding-progress-bar-uploadfile-sftp-operations">Tracking Progress &#8211; DownLoadFile SFTP operations</a></li><li><a href="#aioseo-print-the-progress-on-console">Print the progress on the Console</a></li></ul></div>



<p></p>



<p>Getting access to all the files using the <strong>SSH.NET </strong>library is pretty simple.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting Started</h2>



<p></p>



<p>Create any .NET Core application like a console application,</p>



<p></p>



<p>Add <strong><em>SSH.NET Nuget</em></strong> package as below,</p>



<p></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="162" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg" alt="displaying-progress-of-file-upload-in-a-progressbar-with-ssh-net" class="wp-image-23372" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-300x47.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-768x121.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-785x124.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively.jpg 1435w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p><strong>Package Manager Console,</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Install-Package <a href="https://www.nuget.org/packages/SSH.NET/" target="_blank" rel="noopener" title="">SSH.NET </a>-Version 2020.0.2</pre>



<p></p>



<p><strong>Note</strong>: Please use the latest version.</p>



<p></p>



<p>Here we need to follow the below high-level steps to either download or upload the file below,</p>



<p></p>



<ul class="wp-block-list">
<li>Connect SFTP server</li>
</ul>



<ul class="wp-block-list">
<li>Calculate the file size to be uploaded.</li>
</ul>



<ul class="wp-block-list">
<li>Initialize Progress variable </li>
</ul>



<ul class="wp-block-list">
<li>Define a callback used for tracking the progress bar </li>
</ul>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using SFTPClient</h2>



<p></p>



<p>SSH.NET provides SFTPClient class that lets you connect to the SFTP server securely and access files for </p>



<p>read, write, upload, or download purposes,</p>



<p></p>



<p>Below the sample code read the FTP file and write their name on the console.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [5,10]; title: ; notranslate">
 

using (var client = new SftpClient(&quot;****&quot;, &quot;user&quot;, &quot;****&quot;))
            {
                client.Connect();
             }




</pre></div>


<h2 class="wp-block-heading" id="aioseo-how-to-chnage-default-file-path-in-sftp">Adding Progress bar &#8211; UploadFile SFTP operations</h2>



<p></p>



<p>To implement a progress bar for file transfers using <strong>SFTPClient </strong>in C# with a <em><strong>callback </strong></em>mechanism, you can define a delegate and pass it as a callback parameter to the <code>UploadFile</code>.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-define-a-callback-method"><br>Define a callback method </h3>



<p></p>



<p>Let&#8217;s define the progress callback delegate,</p>



<p></p>



<pre class="wp-block-preformatted">Action progressBarCallback = (uploaded) =&gt;
{
                    uploadedBytes = (long)uploaded;

                    // Calculate the progress percentage
                    progress = (int)((uploadedBytes * 100) / fileSize);

                    // Trackthe progress bar
                    TrackProgress(progress);
  };</pre>



<p></p>



<p>Above Inside the event handlers, we calculate the progress percentage based on the total file size and the size of the uploaded or downloaded bytes.</p>



<p></p>



<p>Then, we call the UpdateProgressBar method to update and display the progress bar in the console.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-tracking-progress-sftp-upload-file">Tracking Progress &#8211; SFTP Upload file </h2>



<p></p>



<p>Here is the complete example for Tracking Progress &#8211; SFTP Upload file.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,29]; title: ; notranslate">
               // Create an SFTP client
                using (var sftpClient = new SftpClient(&quot;Host&quot;, &quot;UserName&quot;, &quot;Passowrd&quot;))
                {
                    // Connect to the SFTP 
                    sftpClient.Connect();

                    // Calculate the file size
                    var fileSize = new FileInfo(localDirectoryFilePath).Length;

                    // Initialize the progress variables
                    long uploadedBytes = 0;
                    int progress = 0;

                    // Define the progress callback delegate
                    Action&lt;ulong&gt; progressBarCallback = (uploaded) =&gt;
                    {
                        uploadedBytes = (long)uploaded;

                        // Calculate the progress percentage
                        progress = (int)((uploadedBytes * 100) / fileSize);

                        // Track the progress bar
                       TrackProgress(progress);

                    };

             using (var uplfileStream = System.IO.File.OpenRead(localDirectoryFilePath))
                {
                    sftpClient.UploadFile(uplfileStream, destinationPath, true, progressBarCallback );
                }

                    // Disconnect from the SFTP server
                    sftpClient.Disconnect();
                }
            }
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-adding-progress-bar-uploadfile-sftp-operations">Tracking Progress &#8211; DownLoadFile SFTP operations</h2>



<p></p>



<p>Similarly, please see the below example for performing Download file operations.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [25]; title: ; notranslate">
            
using (var sftpClient = new SftpClient(&quot;Host, &quot;User&quot;, &quot;Pwd&quot;))
{
      // Connect to the SFTP server
      sftpClient.Connect();
      // Calculate the file size
       var fileSize = sftpClient.GetAttributes(remoteBaseDirectory).Size;

            // Initialize the progress variables
            long downloadedBytes = 0;
            int progress = 0;

            // Define the progress callback delegate
            Action&lt;ulong&gt; progressCallback = (downloaded) =&gt;
            {
                downloadedBytes = (long)downloaded;

                // Calculate the progress percentage
                progress = (int)((downloadedBytes * 100) / fileSize);

                 // Track the progress bar
                  TrackProgress(progress);
            };

            // Download the file with progress reporting
            sftpClient.DownloadFile(remoteBaseDirectory, File.OpenWrite(localDirectoryFilePath), progressCallback);
        }
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-print-the-progress-on-console">Print the progress on the Console</h2>



<p></p>



<p>The <code>TrackProgressBar</code> the method lets you print the progress percentage on Console or UI (if using UI  display purposes) using the calculated progress percentage. </p>



<p></p>



<p></p>



<pre class="wp-block-preformatted">static void TrackProgressBar(int progress)
    {
        Console.Write("\r[{0}{1}] {2}%", new string('#', progress / 10), new string('-', 10 - (progress / 10)), progress);
    }</pre>



<p></p>



<p>That&#8217;s all, as we can see we can leverage a callback parameter to the <strong>UploadFile </strong>and <strong>DownloadFile </strong>methods as supported to track the progress of a long-awaited operation.</p>



<p></p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/how-to-show-track-progress-bar-sftp-file-download-upload-csharp-net/">How to Track Progress of SFTP File Upload/Download in C#.NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/how-to-show-track-progress-bar-sftp-file-download-upload-csharp-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FileZilla FTP Connection timeout issue</title>
		<link>https://thecodebuzz.com/filezilla-ftp-connection-timeout-issue/</link>
					<comments>https://thecodebuzz.com/filezilla-ftp-connection-timeout-issue/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 17 Apr 2023 00:15:00 +0000</pubDate>
				<category><![CDATA[FTP and SFTP]]></category>
		<category><![CDATA[FileZilla FTP Connection timeout]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=27315</guid>

					<description><![CDATA[<p>FileZilla FTP Connection timeout issue Issue Description Using FileZilla gives FTP Connection timeout issue every after 20 seconds. Resolution: Please note that FileZilla has a default timeout setup which is only 20 seconds. This time frame works mostly for the small files. If you have bigger files size like .png or .mpeg or .svg files [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/filezilla-ftp-connection-timeout-issue/">FileZilla FTP Connection timeout issue</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">FileZilla FTP Connection timeout issue</h1>



<h2 class="wp-block-heading">Issue Description</h2>



<p></p>



<p>Using FileZilla gives FTP Connection timeout issue every after 20 seconds.</p>



<p></p>



<figure class="wp-block-image size-full"><img decoding="async" width="771" height="76" src="https://www.thecodebuzz.com/wp-content/uploads/2023/04/image-6.png" alt="" class="wp-image-27316" srcset="https://thecodebuzz.com/wp-content/uploads/2023/04/image-6.png 771w, https://thecodebuzz.com/wp-content/uploads/2023/04/image-6-300x30.png 300w, https://thecodebuzz.com/wp-content/uploads/2023/04/image-6-768x76.png 768w" sizes="(max-width: 771px) 100vw, 771px" /></figure>



<p></p>



<p></p>



<h2 class="wp-block-heading">Resolution:</h2>



<p></p>



<p>Please note that FileZilla has a default timeout setup which is only 20 seconds.</p>



<p></p>



<p>This time frame works mostly for the small files. If you have bigger files size like .png or .mpeg or .svg files etc such file transfer needs more time to transfer the file.</p>



<p></p>



<p>I had a file with a size of over 20k bytes as shown below,</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="267" src="https://www.thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-1024x267.jpg" alt="" class="wp-image-27322" srcset="https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-1024x267.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-300x78.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-768x200.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-785x205.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption>#image_title</figcaption></figure>



<p></p>



<p>To fix such issues, you simply need to increase the timeout by following the below steps,</p>



<p></p>



<ul class="wp-block-list"><li>On Windows, click Edit >> Settings</li></ul>



<p></p>



<ul class="wp-block-list"><li>Under [Connection], update timeout in seconds to the max as per your requirements (default is 20 seconds).</li></ul>



<p></p>



<ul class="wp-block-list"><li>Click [OK] to save your changes and connect again.</li></ul>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/filezilla-ftp-connection-timeout-issue" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="1024" height="454" src="https://www.thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-ftp-1024x454.jpg" alt="FileZilla FTP Connection timeout issue" class="wp-image-27318" srcset="https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-ftp-1024x454.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-ftp-300x133.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-ftp-768x340.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/04/filezilla-connection-timeout-to-sftp-ftp-785x348.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption>#image_title</figcaption></figure>



<p></p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/filezilla-ftp-connection-timeout-issue/">FileZilla FTP Connection timeout issue</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/filezilla-ftp-connection-timeout-issue/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>FTP SSH.NET &#8211; Move or Archive Files with examples</title>
		<link>https://thecodebuzz.com/ftp-ssh-net-move-or-archive-copy-files-with-examples/</link>
					<comments>https://thecodebuzz.com/ftp-ssh-net-move-or-archive-copy-files-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 14 Nov 2022 00:54:05 +0000</pubDate>
				<category><![CDATA[FTP and SFTP]]></category>
		<category><![CDATA[c# ftp library]]></category>
		<category><![CDATA[c# ftpclient]]></category>
		<category><![CDATA[file transfer in c#]]></category>
		<category><![CDATA[ftp move file to another directory]]></category>
		<category><![CDATA[ftp server c# source code]]></category>
		<category><![CDATA[how to create a file in ftp server using c#]]></category>
		<category><![CDATA[how to get file from ftp server in c#]]></category>
		<category><![CDATA[sftp move file to another directory c#]]></category>
		<category><![CDATA[SSH.NET - Move or Archive Files]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=24179</guid>

					<description><![CDATA[<p>FTP SSH.NET &#8211; Move or Archive Files with examples Today in this article, we will see how to perform FTP SSH.NET &#8211; Move or Archive Files with examples using C#.NET code. We will explore this option using the SSH.NET library for .NET/.NET Core. Below is the list of high-level features supported by the SSH library [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/ftp-ssh-net-move-or-archive-copy-files-with-examples/">FTP SSH.NET – Move or Archive Files with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading" id="aioseo-ftp---file-download-and-upload-using-c-net">FTP SSH.NET &#8211; Move or Archive Files with examples</h1>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="333" src="https://www.thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-1024x333.jpg" alt="FTP SSH.NET - Move or Archive Files with examples" class="wp-image-24181" style="width:888px;height:289px" srcset="https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-1024x333.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-300x98.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-768x250.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-1536x499.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples-785x255.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/11/FTP-SSHNET-Move-or-Archive-Files-with-examples.jpg 2027w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we will see how to perform FTP SSH.NET &#8211; Move or Archive Files with examples using C#.NET code.</p>



<p></p>



<p>We will explore this option using the <strong>SSH.NET</strong> library for .NET/.NET Core.</p>



<p></p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-what-is-sftp">What is SFTP</a></li><li><a href="#aioseo-getting-started">Getting Started</a></li><li><a href="#aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using SFTPClient</a></li><li><a href="#aioseo-how-to-chnage-default-file-path-in-sftp">File Move Archive using FTP</a></li><li><a href="#aioseo-copy-file-using-ssh-net-using-downloadfile-or-rename">Copy OR Move File using SSH.NET using DownloadFile or Rename</a></li><li><a href="#aioseo-sftp-read-file-receursively">FTP how to get a list of all files in a Path to Move?</a></li></ul></div>



<p></p>



<div data-schema-only="false" class="wp-block-aioseo-faq" id="aioseo-what-is-sftp"><h3 class="aioseo-faq-block-question">What is SFTP<br></h3><div class="aioseo-faq-block-answer">
<p>SFTP (SSH File Transfer Protocol) is a secure file transfer protocol. It runs over the&nbsp;<a href="https://www.ssh.com/ssh/protocol" target="_blank" rel="noopener">SSH protocol</a>. </p>



<p></p>



<p>It supports the full security and authentication functionality of SSH.</p>



<p></p>
</div></div>



<p></p>



<p>Below is the list of high-level features supported by the <strong>SSH </strong>library (but not limited to),</p>



<p></p>



<ul class="wp-block-list">
<li>Provide SFTP functionality for both synchronous and asynchronous operations.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Provides SCP functionality</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li><strong>Execution of SSH command using both synchronous and asynchronous methods</strong></li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Provide a status report for upload and download <strong>SFTP </strong>operations to allow accurate progress bar implementation.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports public-key, <strong>password</strong>, and keyboard-interactive authentication methods.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports two-factor or higher authentication</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports <strong>SOCKS4</strong>, <strong>SOCKS5</strong>, and <strong>HTTP </strong>Proxy</li>
</ul>



<p></p>



<p>Getting access to all the files using the <strong>SSH.NET </strong>library is pretty simple.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting Started</h2>



<p></p>



<p>Create any .NET Core application like a console application,</p>



<p></p>



<p>Add <strong><em>SSH.NET Nuget</em></strong> package as below,</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="162" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg" alt="FTP SSH.NET - Move or Archive Files with examples" class="wp-image-23372" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-300x47.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-768x121.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-785x124.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively.jpg 1435w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p><strong>Package Manager Console,</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Install-Package SSH.NET -Version 2020.0.2</pre>



<p></p>



<p><strong>Note</strong>: Please use the latest version.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using SFTPClient</h2>



<p></p>



<p>SSH.NET provides SFTPClient class that lets you connect to the SFTP server securely and access files for </p>



<p>read, write, upload, or download purposes,</p>



<p></p>



<p>Below the sample code read the FTP file and write their name on the console.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [5,10]; title: ; notranslate">
 

using (var client = new SftpClient(&quot;****&quot;, &quot;user&quot;, &quot;****&quot;))
            {
                client.Connect();
                ListDirectory(client, &quot;.&quot;);
                foreach (var file in files)
                {
                  Console.WriteLine(file.FullName);
                }
             }




</pre></div>


<p></p>



<p>The above ListDirectory uses the default path to fetch a file from the SFTP server.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-how-to-chnage-default-file-path-in-sftp">File Move Archive using FTP</h2>



<p></p>



<p>File move or archive file from a remote file path is pretty simple once the connection is established successfully.</p>



<p></p>



<p>Use the below code to Move or Archive the file via <strong>SftpClient</strong></p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [3,10,16]; title: ; notranslate">
 

using (var client = new SftpClient(&quot;****&quot;, &quot;user&quot;, &quot;****&quot;))
            {
                client.Connect();
                ListDirectory(client, &quot;.&quot;);
                foreach (var file in files)
                {
                Console.WriteLine(file.FullName);

                var fileMove = client.Get(file.FullName);
                fileMove.MoveTo(destinationPath);

                }

               client.Disconnect();
             }




</pre></div>


<p></p>



<p>In the above code,</p>



<p></p>



<p><strong><em>destinationPath </em></strong>&#8211; This is the file path where the file will be moved via SFTP/FTP.</p>



<p></p>



<p><strong><em>Get </em></strong>method gives a reference of the file from the remote location by returning Renci.SshNet.Sftp.SftpFile file object. </p>



<p></p>



<p><strong><em>MoveTo</em></strong>&#8211; Moves a specified file to a new location on a remote machine. You can use the same file name or provide a name of your choice.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-copy-file-using-ssh-net-using-downloadfile-or-rename">Copy OR Move File using SSH.NET using DownloadFile or Rename</h2>



<p></p>



<p>One can easily use the DownloadFile or Rename method to copy or archive the files as explained below in the code.</p>



<p></p>



<pre class="wp-block-preformatted">using (var client = new SftpClient(host, username, password))
        {
            client.Connect();

            using (var fileStream = System.IO.File.Create(localDestinationPath))
            {
                client.DownloadFile(remoteFilePath, fileStream);
            }

            client.Disconnect();
        }</pre>



<p><strong>OR</strong></p>



<pre class="wp-block-preformatted">using (var client = new SftpClient(host, username, password))
        {
            client.Connect();

            // Rename the file to move it
            client.RenameFile(sourceFilePath, destinationFilePath);

            client.Disconnect();
        }
</pre>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-sftp-read-file-receursively">FTP how to get a list of all files in a Path to Move?</h2>



<p></p>



<p>Below is the complete implementation for the <strong><em>ListDirectory()</em></strong> custom method which returns all the files available from the specified root folder and subfolders.</p>



<p></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="668" height="399" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C.jpg" alt="FTP SSH.NET - Move or Archive Files with examples" class="wp-image-23374" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C.jpg 668w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C-300x179.jpg 300w" sizes="auto, (max-width: 668px) 100vw, 668px" /></figure>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/ftp-ssh-net-move-or-archive-copy-files-with-examples/">FTP SSH.NET – Move or Archive Files with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/ftp-ssh-net-move-or-archive-copy-files-with-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Retrieve a file from a server via SFTP-.NET C#</title>
		<link>https://thecodebuzz.com/retrieve-a-file-from-a-server-via-sftp-net-csharp-net-core-ftp/</link>
					<comments>https://thecodebuzz.com/retrieve-a-file-from-a-server-via-sftp-net-csharp-net-core-ftp/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 01 Sep 2022 12:47:00 +0000</pubDate>
				<category><![CDATA[FTP and SFTP]]></category>
		<category><![CDATA[c# sftp download file to memorystream]]></category>
		<category><![CDATA[download directory from sftp using c#]]></category>
		<category><![CDATA[download file from ftp server using c#]]></category>
		<category><![CDATA[how to get list of files from sftp server in c#]]></category>
		<category><![CDATA[how to read csv file from sftp server in c#]]></category>
		<category><![CDATA[how to read file from sftp server in c#]]></category>
		<category><![CDATA[Retrieve a file from a server via SFTP-.NET C#]]></category>
		<category><![CDATA[sftp in asp net c#]]></category>
		<category><![CDATA[ssh.net sftp download example c#]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=23385</guid>

					<description><![CDATA[<p>Retrieve a file from a server via SFTP- .NET C# Today in this article, we will see how to Retrieve a file from a server via SFTP or FTP &#8211; .NET C#. We will use a .NET library called SSH.NET to perform SFTP Get a list of Files recursively. SSH.NET library works fine in regular [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/retrieve-a-file-from-a-server-via-sftp-net-csharp-net-core-ftp/">Retrieve a file from a server via SFTP-.NET C#</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Retrieve a file from a server via SFTP- .NET C#</h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="333" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-1024x333.jpg" alt="Retrieve a file from a server via SFTP" class="wp-image-23377" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-1024x333.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-300x98.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-768x250.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-1536x499.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C-785x255.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/09/SFTP-Get-a-list-of-file-and-directory-recursively-C.jpg 2027w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we will see how to Retrieve a file from a server via SFTP or FTP &#8211; .NET C#. </p>



<p></p>



<p>We will use a .NET library called <strong>SSH.NET</strong> to perform SFTP Get a list of Files recursively. SSH.NET library works fine in regular .NET and .NET core seamlessly.</p>



<p></p>



<p>SSH.NET is a <strong>Secure Shell (SSH-2)</strong> library for .NET which provides the capability to execute various <strong>SSH </strong>commands and provides <strong>SFTP</strong> ( Secured File transfer) features like Upload or download.</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-what-is-sftp">What is SFTP</a></li><li><a href="#aioseo-getting-started">Getting Started &#8211; Install Nuget SSH.NET</a></li><li><a href="#aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using C# .NET- SFTPClient</a></li><li><a href="#aioseo-sftp-read-file-receursively">SFTP &#8211; Get a list of all files</a></li><li><a href="#aioseo-sftp-read-file-recursively">SFTP Read file and download it</a></li></ul></div>



<p></p>



<div data-schema-only="false" class="wp-block-aioseo-faq" id="aioseo-what-is-sftp"><h3 class="aioseo-faq-block-question">What is SFTP<br></h3><div class="aioseo-faq-block-answer">
<p>SFTP (SSH File Transfer Protocol) is a secure file transfer protocol. </p>



<p></p>



<p>It runs over the <a href="https://www.ssh.com/ssh/protocol" target="_blank" rel="noopener">SSH protocol</a>. It supports the full security and authentication functionality of SSH.</p>
</div></div>



<p></p>



<p>Below is the list of high-level features supported by the <strong>SSH </strong>library (but not limited to),</p>



<p></p>



<ul class="wp-block-list">
<li>Provide SFTP functionality for both synchronous and asynchronous operations.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Provides SCP functionality</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li><strong>Execution of SSH command using both synchronous and asynchronous methods</strong></li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Provide a status report for upload and download <strong>SFTP </strong>operations to allow accurate progress bar implementation.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports public-key, password, and keyboard-interactive authentication methods.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports two-factor or higher authentication</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Supports SOCKS4, SOCKS5, and HTTP Proxy</li>
</ul>



<p></p>



<p>Getting access to all the files using the <strong>SSH.NET </strong>library is pretty simple.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting Started &#8211; Install Nuget SSH.NET</h2>



<p></p>



<p>Create any .NET Core application like a console application,</p>



<p></p>



<p>Add <strong><em>SSH.NET Nuget</em></strong> package as below,</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="162" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg" alt="Retrieve a file from a server via SFTP" class="wp-image-23372" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-1024x162.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-300x47.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-768x121.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-785x124.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively.jpg 1435w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p><strong>Package Manager Console,</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">Install-Package SSH.NET -Version 2020.0.2</pre>



<p></p>



<p><strong>Note</strong>: Please use the latest version</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-connect-to-sftp-using-sftpclient">Connect to SFTP using C# .NET- SFTPClient</h2>



<p></p>



<p>SSH.NET provides a simple class  SFTPClient which lets you connect to the SFTP server securely and access files for </p>



<p>read, write, upload, or download purposes,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [5,10]; title: ; notranslate">
 

using (var client = new SftpClient(&quot;SFTP server IP&quot;, &quot;username&quot;, &quot;password&quot;))
            {
                client.Connect();
                Console.WriteLine(&quot;Connected to host&quot;);
                client.ChangeDirectory(remoteBaseDirectory);

                Console.WriteLine(&quot;Changed directory to {0}&quot;, remoteBaseDirectory);
                Console.WriteLine(&quot;Listing directory:&quot;);

                ListDirectory(client, &quot;.&quot;);
                foreach (var file in files)
                {
                  Console.WriteLine(file.FullName);
                }
             }




</pre></div>


<p></p>



<p>Above <em><strong>ChangeDirectory</strong></em>() method setup the <em><strong>remoteBaseDirectory </strong></em>specified path as the base path for the recursive function to get all files from the main and subfolder.</p>



<p></p>



<p>If not used, the default location will be used as the base path.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-sftp-read-file-receursively">SFTP &#8211; Get a list of all files </h2>



<p></p>



<p>Below is the complete implementation for the <strong><em>ListDirectory()</em></strong> custom method which returns all the files available from the specified root folder and subfolders.</p>



<p></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="668" height="399" src="https://www.thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C.jpg" alt="SSH.NET SFTP Get a list of files or directories recursively" class="wp-image-23374" srcset="https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C.jpg 668w, https://thecodebuzz.com/wp-content/uploads/2022/09/SSHNET-SFTP-Get-a-list-of-files-recursively-C-300x179.jpg 300w" sizes="auto, (max-width: 668px) 100vw, 668px" /></figure>



<p></p>



<p>The above method once executed, return all the files from the provided root folder.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-sftp-read-file-recursively">SFTP Read file and download it</h2>



<p></p>



<p>Let&#8217;s now read the FTP file iteratively.</p>



<p></p>



<p>Below we are reading each file from the FTP location and downloading it to the local or destination folder.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">

       foreach (var file in files)
                {
                    Console.WriteLine(file.FullName);
                    using (Stream fileStream = File.Create($&quot;{destinationPath}{&quot;/&quot;}{ 
                    file.Name}&quot;))
                    {
                        client.DownloadFile(file.FullName, fileStream);
                        
                    }
              }  


</pre></div>


<p></p>



<p>Where &#8220;<strong>destinationPath</strong>&#8221;  is your custom path where you want to download/store the file </p>



<p></p>



<p></p>



<p><strong>References </strong>: </p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/powershell-script-upload-download-file-google-cloud-storage-bucket/" target="_blank" rel="noopener" title="Powershell Upload, Download file Google Cloud Storage Bucket">Powershell Upload, Download file Google Cloud Storage Bucket</a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/retrieve-a-file-from-a-server-via-sftp-net-csharp-net-core-ftp/">Retrieve a file from a server via SFTP-.NET C#</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/retrieve-a-file-from-a-server-via-sftp-net-csharp-net-core-ftp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
