Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Error Handling
Suggested answer

SFTP flow fails for some of the files (the others work perfectly fine)

(1) ShareShare
ReportReport
Posted on by
Hello! 
 
I have a problem with a flow in Power Automate. There is a flow which every time a file is created in OneDrive's directory replicates this file to a remote server via SFTP connection.
 
This flow processes a few hundreds files every day. For most of them the flow works without any issue, it normally takes < 1 second to process the file. However, every day there are 2-3-5 cases when the file transfer fails:
The error message says "BadGateway" with the status 502, error comment is "An established connection was aborted by the server." That is strange because those files are similar to hundreds of other files which go through to the final destination without a problem. 
 
We had some problems with file name's length (>256 symbols or something like this) some time ago, but after that case we implemented shortening of file name, these files we're having problems with have the same file name length as other files (nearly 190 symbols normally). The file size is normal as well, about 30-50 kb. 
 
On Power Automate side we dont have much more details regarding why this is happening, apart from the error code I've mentioned. Whats even more strange, our network admin told me this 502 error code is related to HTTP protocol, not SFTP, so its unclear why do we even get this. Likely this error is whats being passed to us from some intermediate servers on Microsoft side, but basically this is a black box for us.
 
With this in mind, I wanted to ask community for help, because I've ran out of options. What can be the reason that 95% of files every day are being transferred via SFTP protocol successfully, but 5% of files fail? What can be the difference between those files, to cause a problem when uploading to a server?
 
Thank you!
  • Suggested answer
    Michael E. Gernaey Profile Picture
    44,261 Super User 2025 Season 1 on at
    SFTP flow fails for some of the files (the others work perfectly fine)
     
    Not sure if you got an answer but I wanted to share some thoughts
     
    1. I notice that in the Failure you show that there was a flow triggered, I dont want to say a minute apart as its possible it was not a full minute
    This and the process itself that copies the files there, can keep the files locked which would for sure cause this issue as well as things like Name, or File Size.
     
    My suggestion, would be to add the proper Error Handling, so that it can be captured, and immediately retried, or put a small delay in.
     
    I cannot see your flow so I have to essentially make up this for you but think on it like this
     
    Flow Triggers
     
    Add a variable (boolean) call it FileCopied, set to false
    Add a variable (int) call it RetryCount set to 0
    Add a variable (int) call it MaxRetries set to 5 (or whatever you want).
     
    Add a Do Until, make it run until either
    MaxRetries > 5 Or FileCopied = true
     
    Now inside the do until you need to create a Try Catch
     
    Add a Scope call it Try
     
    Add two scopes in Parallel below it
    rename one to Success
    rename other to Failed
     
    In the Try scope, ass your code to try to copy the file
    Set the RunAfter Configuration for the Success Scope to.. well Successs :-)
    Set the RunAfter Configuration for the Failed to Failed, Skipped, TimeOut
     
    Inside the Success scope add a Set variable
    Set the FileCopied to true
    Ignore the RetryCount
     
    Inside the Failed scope add 1 Increment Variable
    Since FileCopied was defaulted to False we dont need to set that there
    instead, use the Increment Variable on the RetryCount and add 1
     
    Doing this will cause it to retry 5 times, where-in the FileCopied would be False and the RetryCount would be 6. This would cause it to kick you out of the DoUntil
    OR
    Since in the Success you set FileCopied to true, it would kick you out.
     
    Outside of both scopes, but after the Do  Until add a Condition
    In the Condition check if
    FileCopied is equal to true (the expression not the string)
     
    In the Yes, you can use Terminate Action set to Success
    in the No, you can use Terminate Action set to Failed
     
    You can even log a message if you want, but you would know for a fact it tried 5 times and exitted because thats your logic.
     
    Failures will happen, we just need to work around them.  
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1

Featured topics