WinSCP SFTP batch/PS script would not transfer the entire file

Hello!

I am trying to sftp a file that is alomost 2.5 GB using WinSCP. When I drag and drop using WinSCP the entire file gets transferred. I am trying to automate this using Batch file (unsuccessful) then Power Shell (unsuccessful again). When I use these scripts, only 2/3rds of the file gets transferred. No error is being shown as well and transfer says complete.

See attached file for the file sizes.file_transfer.jpg
Is there a solution to this?

***********************************************************
Batch File
***********************************************************
/c ""C:\Program Files (x86)\WinSCP\WinSCP.com" /command "option batch on" "option confirm off" "option transfer binary" "open sftp://<user name>:<password>@<server address/path> -hostkey="*" " "put ""<File name & path here>"" " "close" "exit"


***********************************************************
Power Shell Script
***********************************************************
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"


$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "XYZ"
        UserName = "ABC"
        Password = "PQR"
        SshHostKeyFingerprint = "BBB"
    }


# Connect
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
# Don't use the resumable option, -resumesupport

$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off

$FilePath = "<FILEPATH>\*"

Test-path $FilePath

#Get-ChildItem $FilePath

#Get-FileHash $FilePath


$transferResult = $session.PutFiles($FilePath, "/inbound/", $False, $transferOptions)


$transferResult.Transfers

$transferResult.Check()


$timer.ElapsedMilliseconds

ForEach ($transfer in $transferResult.Transfers)
        {
            Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
        }

$session.Dispose()


Thanks!
K
kbcoderAsked:
Who is Participating?
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
In the powershell part:
I'd embrace the script in a try/catch loop so If there's anything wrong the catch will get the exception.

try{
    $session = New-Object WinSCP.Session
    $session.Open($sessionOptions)
    
    $transferOptions = New-Object WinSCP.TransferOptions
    $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
    # Don't use the resumable option, -resumesupport
    
    $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off 
    
    $FilePath = "<FILEPATH>\*"
    
    #Test-path $FilePath
    #Get-ChildItem $FilePath
    #Get-FileHash $FilePath
    
    
    $transferResult = $session.PutFiles($FilePath, "/inbound/", $False, $transferOptions)
    $transferResult.Transfers
    $transferResult.Check()
    
    $timer.ElapsedMilliseconds
    
    ForEach ($transfer in $transferResult.Transfers){
        Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
    }
    
    $session.Dispose();
}
catch{
    $ErrorMessage = $_.Exception.Message
    #$FailedItem = $_.Exception.ItemName
    Write-Error $ErrorMessage
}

    

Open in new window

0
 
kbcoderAuthor Commented:
Jose, I will try that out and see what happens. Thanks for your reply.
0
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Np let's start the troubleshoot for something, maybe it can be a kind of "timeout" of the winscp session, it should be a variable or property that manages that time, something like $session.timeout= "XX"
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
kbcoderAuthor Commented:
Jose, about the timeout part of it, I tried to sftp the file 2 times, the first time it took about 55 mins and the second time 1 hr 55 mins and both the times the size that was transferred was exactly the same.
0
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Well I don't have right now a test environment (I'm out of town)  if you can provide it I'll gladly connect it and help.
Either way I've found this
https://winscp.net/forum/viewtopic.php?t=24665
0
 
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
No follow up
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.