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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kbcoderAuthor Commented:
Jose, I will try that out and see what happens. Thanks for your reply.
0
Jose Gabriel Ortega CastroCEOCommented:
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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 CastroCEOCommented:
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 CastroCEOCommented:
No follow up
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.