SFTP Upload - how verify upload successful

Advertisement

andyk
Joined:
Posts:
4

SFTP Upload - how verify upload successful

Hello All,

First time poster, I am looking to script the upload of files via SFTP.
I can see some samples for this.

However, I also want to confirm that the file that has uploaded is a) verified to be uploaded and/or is comparable to the source file.
Ideally an error would generate a follow on action (call an email script etc)

Reason being that from the source side we would upload and archive off the file - but not necessarily be sure the upload has happened due to connectivity issue etc.

Can anyone help me with this?

Many Thanks

Andy

Reply with quote

Advertisement

andyk
Joined:
Posts:
4

Hi Martin,
Thanks for the response.
I ended up coding it like this, does that look like it would give the correct result?
I have tested it as far as I can without simulating a coms down.

# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host "Upload of $($transfer.FileName) succeeded, moving to Archive"
Move-Item $transfer.FileName $ArchivePath
}
else
{
Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
}
}

Reply with quote

andyk
Joined:
Posts:
4

Hi Martin,

Sorry, I thought from the original post that it would be clear:

'However, I also want to confirm that the file that has uploaded is a) verified to be uploaded and/or is comparable to the source file.
Ideally an error would generate a follow on action (call an email script etc) '

From my side, the code looks like it should upload the file and email on completion, or if there it is a failure it emails the message.
In testing it has worked when the file has not been present or a permissions issue, the only test I have not been able to perform is if the transmission is broken.

Thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar

andyk wrote:

the only test I have not been able to perform is if the transmission is broken.
OK, the code will print "Upload of ... failed" if connection is broken while uploading the file (and reconnect did not succeed).

Reply with quote

Advertisement

You can post new topics in this forum