Skip to content

Commit fddd48a

Browse files
add rekey check to sftp client and use reletave path to file in test case
1 parent 462d77b commit fddd48a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

.github/workflows/windows-sftp.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ jobs:
327327
$sftpPath = $env:SFTP_PATH
328328
$workDir = (Get-Location).Path
329329
$largeFile = Join-Path $workDir "large_test.dat"
330-
$getDest = Join-Path $workDir "large_test_copy.dat"
330+
$getDest = "large_test_copy.dat" # relative path so SFTP client writes to cwd
331331
332332
# Create 3GB file: one random 10MB chunk repeated 307x + 2MB
333333
Write-Host "Creating 3GB test file..."
@@ -355,6 +355,7 @@ jobs:
355355
$putCommands | Out-File -FilePath sftp_put_commands.txt -Encoding ASCII
356356
$proc = Start-Process -FilePath $sftpPath `
357357
-ArgumentList "-u", "testuser", "-P", $env:TESTUSER_PASSWORD, "-h", "localhost", "-p", "${{env.TEST_PORT}}" `
358+
-WorkingDirectory $workDir `
358359
-RedirectStandardInput "sftp_put_commands.txt" `
359360
-RedirectStandardOutput "sftp_put_out.txt" `
360361
-RedirectStandardError "sftp_put_err.txt" `
@@ -368,12 +369,13 @@ jobs:
368369
}
369370
Write-Host "PUT succeeded"
370371
371-
# SFTP GET (download)
372+
# SFTP GET (download) - use relative path so file lands in working dir
372373
Write-Host "SFTP GET 3GB file..."
373-
$getCommands = "get /large_test.dat $getDest`nquit"
374+
$getCommands = "get /large_test.dat large_test_copy.dat`nquit"
374375
$getCommands | Out-File -FilePath sftp_get_commands.txt -Encoding ASCII
375376
$proc2 = Start-Process -FilePath $sftpPath `
376377
-ArgumentList "-u", "testuser", "-P", $env:TESTUSER_PASSWORD, "-h", "localhost", "-p", "${{env.TEST_PORT}}" `
378+
-WorkingDirectory $workDir `
377379
-RedirectStandardInput "sftp_get_commands.txt" `
378380
-RedirectStandardOutput "sftp_get_out.txt" `
379381
-RedirectStandardError "sftp_get_err.txt" `
@@ -387,9 +389,10 @@ jobs:
387389
}
388390
Write-Host "GET succeeded"
389391
390-
# Verify integrity
392+
# Verify integrity (file is in $workDir from GET with relative path)
393+
$getDestPath = Join-Path $workDir "large_test_copy.dat"
391394
$expectedHash = (Get-Content large_test.dat.sha256).Trim()
392-
$actualHash = (Get-FileHash -Path $getDest -Algorithm SHA256).Hash
395+
$actualHash = (Get-FileHash -Path $getDestPath -Algorithm SHA256).Hash
393396
if ($expectedHash -ne $actualHash) {
394397
Write-Host "ERROR: SHA256 mismatch - PUT/GET corruption"
395398
Write-Host "Expected: $expectedHash"

examples/sftpclient/sftpclient.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ static int doCmds(func_args* args)
769769

770770
ret = wolfSSH_SFTP_STAT(ssh, pt, &atrb);
771771
err = wolfSSH_get_error(ssh);
772-
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE)
773-
&& ret != WS_SUCCESS);
772+
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE ||
773+
err == WS_REKEYING) && ret != WS_SUCCESS);
774774
if (ret != WS_SUCCESS) {
775775
if (SFTP_FPUTS(args, "Error changing directory\n") < 0) {
776776
err_msg("fputs error");
@@ -857,8 +857,8 @@ static int doCmds(func_args* args)
857857

858858
ret = wolfSSH_SFTP_CHMOD(ssh, pt, mode);
859859
err = wolfSSH_get_error(ssh);
860-
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE)
861-
&& ret != WS_SUCCESS);
860+
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE ||
861+
err == WS_REKEYING) && ret != WS_SUCCESS);
862862
if (ret != WS_SUCCESS) {
863863
if (SFTP_FPUTS(args, "Unable to change permissions of ") < 0) {
864864
err_msg("fputs error");
@@ -914,8 +914,8 @@ static int doCmds(func_args* args)
914914

915915
ret = wolfSSH_SFTP_RMDIR(ssh, pt);
916916
err = wolfSSH_get_error(ssh);
917-
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE)
918-
&& ret != WS_SUCCESS);
917+
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE ||
918+
err == WS_REKEYING) && ret != WS_SUCCESS);
919919
if (ret != WS_SUCCESS) {
920920
if (ret == WS_PERMISSIONS) {
921921
if (SFTP_FPUTS(args, "Insufficient permissions\n") < 0) {
@@ -967,8 +967,8 @@ static int doCmds(func_args* args)
967967

968968
ret = wolfSSH_SFTP_Remove(ssh, pt);
969969
err = wolfSSH_get_error(ssh);
970-
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE)
971-
&& ret != WS_SUCCESS);
970+
} while ((err == WS_WANT_READ || err == WS_WANT_WRITE ||
971+
err == WS_REKEYING) && ret != WS_SUCCESS);
972972
if (ret != WS_SUCCESS) {
973973
if (ret == WS_PERMISSIONS) {
974974
if (SFTP_FPUTS(args, "Insufficient permissions\n") < 0) {

0 commit comments

Comments
 (0)