Tag: FTP

Windows Server FTP

Install FTP Server on Windows Server

Windows Server has IIS build in, which also offers an FTP server option. The File Transfer Protocol (FTP) is still a very popular protocol that allows users to simply upload and download files. Of course today you have more modern options, however, it is still very often used and a lot of legacy applications still support it. In this blog post, I wanna quickly go rough how you can install the FTP Server on Windows Server. I do this on a brand new Windows Server 2019 operating system, however, it didn’t really change since early Windows Server versions.

Install FTP Server Feature on Windows Server

Install FTP on Windows Server using PowerShell

First, you will need to install the FTP feature. I usually simply do that using PowerShell to install the FTP Server feature in Windows Server. You can also do that using the Server Manager. However, if you want to use PowerShell, you can use the following command:

 
Install-WindowsFeature Web-Ftp-Server -IncludeAllSubFeature -IncludeManagementTools -Verbose


Cyberduck for Windows

Today I saw that my favorite FTP tool on Mac also released a version for Windows. The software is still beta but if you like the Mac version you will also like the Windows version.

Cyberduck for WindowsCyberduck for WindowsI don’t think it will replace Total Commander for me, but we will see. You can find more information about the new Windows release of Cyberduck on the Cyberduck Homepage.



Windows Server FTP

PowerShell FTP upload and download

A friend asked me if Powershell can do simple file up and downloads. My answer was, yes of course, very easy. So this is a post with a little information about how you can do a FTP Upload or a FTP Download using Powershell. To be clear, of course you can do much more with PowerShell and FTP. But this post should show you the basic function of FTP transfers in Powershell based on the .NET Framework. With that here is how PowerShell FTP works:

FTP Upload file using PowerShell

This is how you can upload a file using FTP with PowerShell.

# Config
$Username = "FTPUSER"
$Password = "[email protected]"
$LocalFile = "C:\Temp\file.zip"
$RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip"
 
# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = gc -en byte $LocalFile
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup
$Run.Close()
$Run.Dispose()

FTP download file using PowerShell

And this is how you can download files from an FTP server using PowerShell.

# Config
$Username = "FTPUSER"
$Password = "[email protected]"
$LocalFile = "C:\Temp\file.zip"
$RemoteFile = "ftp://thomasmaurer.ch/downloads/files/file.zip"
 
# Create a FTPWebRequest
$FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
$FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$FTPRequest.UseBinary = $true
$FTPRequest.KeepAlive = $false
# Send the ftp request
$FTPResponse = $FTPRequest.GetResponse()
# Get a download stream from the server response
$ResponseStream = $FTPResponse.GetResponseStream()
# Create the target file on the local system and the download buffer
$LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create)
[byte[]]$ReadBuffer = New-Object byte[] 1024
# Loop through the download
do {
$ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)
$LocalFileFile.Write($ReadBuffer,0,$ReadLength)
}
while ($ReadLength -ne 0)

So let me know how FTP file transfers with PowerShell are working for you. Scenarios I have used this are simple automation tasks where we needed to upload or download some files.



Solved: Cannot download File from IIS6 FTP

Today we a ticket which was escalated by the second level support to the engineering. A customer could not download, remove or rename the file via FTP. The Hosting is running on a Windows Server 2003 R2 with IIS6. After checking the file on the filesystem I saw that the filename had a space in before.

Normalfilename:

“filename.html”

Wrongfilename:

” filename.html”

You cannot really name a file like that with a windows machine. But Linux and Unix systems like Mac OS X allow this.

After renaming the file to a normal Windows filename, the customer you download the file again.

Btw you can simple rename the file with powershell

Rename-Item " filename.html" "newfilename.html"