TransWikia.com

Resume uploading with built-in Windows FTP client

Super User Asked by Vlad Novakovsky on December 29, 2020

Is it possible to resume uploading with built-in Windows FTP client after FTP client failure/disconnection from previous point?

For example, how to achieve following scenario: build-in FTP client uploads 40% of file, connection was lost, client reconnects and starts uploading of the rest 60% of file? Other FTP clients capable to do this but I restricted by using only software available just after Windows installation.

One Answer

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
    $winscp_version = "5.17.9"
    $winscp_archive = "WinSCP-$winscp_version-Automation.zip"
    Write-Host "Downloading $winscp_archive ..."
    $url =
        "https://sourceforge.net/projects/winscp/files/WinSCP/" +
        $winscp_version + "/" + $winscp_archive + "/download"
    $webclient.DownloadFile($url, $winscp_archive)
    Write-Host "Done"

    Write-Host "Extracting $winscp_archive ..."
    $shell = New-Object -ComObject Shell.Application    

    $current_path = [string](Resolve-Path ".")
    $winscp_archive_path = [string](Resolve-Path $winscp_archive)
    $winscp_archive_folder = $shell.NameSpace($winscp_archive_path)
    $current_folder = $shell.NameSpace($current_path)
    $copy_options = 4 -bor 16 # SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL
    $current_folder.CopyHere($winscp_archive_folder.Items(), $copy_options)
    Write-Host "Done"
}

Add-Type -Path $winscp_assembly

$ftp_host = "ftp.example.com"
$ftp_path = "/target/path/"
$upload_path = "C:bigfile.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

(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.

Correct answer by Martin Prikryl on December 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP