White search icon
News
Upload images with FTP in ASP.NET Core
ASP.NET Core

Upload images with FTP by form in ASP.NET Core

Original YouTube Logo

Article have related YouTube video

Uploading images using FTP is one of the best and simplest ways to send images between your webapp/website to the ftp-server or web-server. In this article i will show you how you do it in ASP.NET Core.

|

ASP.NET Core
Images
C#
FTP

So in this example i use er simple form for the cshtml file, where we send the image to our codebehind file by using the type 'file' in the input field.

You can go an put the form whereever you need to upload some images from.

The next part is a little bit more complicated, but don't worry it is not rocket science. There is 3 methods and a timestamp property in my example that you can include in your project.

First of all there is a OnPostAsync method that is being called when the form is submitted. I then store the image file in a variable, create a timestamp using the second method GetTimestamp.

Finally I call the Upload method that takes one parameter which is the image that have the data type IFormFile. In the Upload method I create a url string that will also create the file-name with a timestamp so you dont get errors if it already exists.

I then create a new FtpWebRequest instance that we can insert credentials and a method to called WebRequestMethods.Ftp.UploadFile.

At last I stream the file and copy it to the server.

Here you can see the whole index.cs file:

You can also go and download the FTP project here


Like what you see?

Buy me a coffee

ZetBit on Spotify

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.