Resume uploading with built-in Windows FTP client
No, the Windows command-line ftp.exe
does not support transfer resuming.
But you can just automatically download any small 3rd party portable command-line FTP client that supports automatic resume and use that.
For example the following PowerShell code downloads WinSCP .NET assembly package, extracts it and starts a resumable upload:
$winscp_assembly = "WinSCPnet.dll"
if (Test-Path $winscp_assembly)
{
Write-Host "WinSCP already downloaded"
}
else
{
$webclient = New-Object System.Net.WebClient
$padUrl = "https://winscp.net/pad/winscp.xml"
$pad = [xml]$webclient.DownloadString($padUrl)
$winscpVersion = $pad.XML_DIZ_INFO.Program_Info.Program_Version
if (-not $winscpVersion)
{
throw "Cannot find latest version of WinSCP"
}
Write-Host "Latest version of WinSCP is $winscpVersion"
$winscpArchive = "WinSCP-$winscpVersion-Automation.zip"
Write-Host "Downloading $winscpArchive ..."
$url =
"https://sourceforge.net/projects/winscp/files/WinSCP/" +
$winscpVersion + "/" + $winscpArchive + "/download"
$webclient.DownloadFile($url, $winscpArchive)
Write-Host "Done"
Write-Host "Extracting $winscpArchive ..."
Expand-Archive $winscpArchive .
Write-Host "Done"
}
Add-Type -Path $winscp_assembly
$ftp_host = "ftp.example.com"
$ftp_path = "/target/path/"
$upload_path = "C:\big\file.dat"
Write-Host "Starting resumable upload of $upload_path to $ftp_host ..."
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = $ftp_host
UserName = "username"
Password = "password"
}
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
$session.PutFiles($upload_path, $ftp_path).Check()
To run the PowerShell script (upload.ps1
) use:
powershell.exe -File upload.ps1 -ExecutionPolicy Bypass
The script uses PowerShell 5 Expand-Archive
cmdlet. If you need to use older version of PowerShell, check an old revision of this answer for a solution with use of Shell.Application
object.
(I'm the author of WinSCP)
Another option is to implement the resume manually using FtpWebRequest
.
See How to continue or resume FTP upload after interruption of internet.
Again you can use the FtpWebRequest
from a PowerShell script. See Upload files with FTP using PowerShell.