Can upload files in GUI but not PowerShell using WinSCP
I have successfully (finally!) gotten large files to upload to an SFTP site with the GUI. I tried getting the setup identical in the PowerShell script using WinSCP dll. However, only the small files work in the PS script process. The large files still give me an error in the PS script process. It still appears to creating a temporary file for large file transfers even though I believe I have it set properly to not do so. See below ...
Additionally, I am including below the code from the PS script for review, also edited for privacy.
I am attaching the log file from the GUI where the files worked as well as the log file from when the PS script had all the same settings, as best that I can tell, but failed for the large file. I have edited the files for privacy. Please compare and let me know what I am doing wrong.Error: Exception calling "Check" with "0" argument(s): "Cannot overwrite remote file '/REMOTEPATH/70d0ff59-d4a7-4648-b106-4e36ef4f550d.txt'.$$
Press 'Delete' to delete the file and create new one instead of overwriting it.$$ Permission denied.
Error code: 3
Error message from server (en): Permission denied"
Additionally, I am including below the code from the PS script for review, also edited for privacy.
################ Send to SFTP ######################## try { # Load WinSCP .NET assembly Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"; #pass the new file to secure FTP # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "HOST NAME" UserName = "USERNAME" Password = 'PASSWORD' SshHostKeyFingerprint = "ssh-dss 1024 FINGER PRINT" Timeout = 6000 } $session = New-Object WinSCP.Session; try { $session.SessionLogPath = '\\NGN-IMAGE\NCTracks\Logs\winscp.log'; ## Connect $session.Open($sessionOptions); $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.AddRawSettings("NewerOnly", "0"); $transferOptions.AddRawSettings("PreserveTimeDirs", "0"); $transferOptions.AddRawSettings("ExcludeHiddenFiles", "0"); $transferOptions.AddRawSettings("ExcludeEmptyDirectories", "0"); $transferOptions.AddRawSettings("EncryptNewFiles", "1"); $transferOptions.AddRawSettings("SendBuf", "0"); $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off $transferOptions.FilePermissions = $Null # This is default $transferOptions.PreserveTimestamp = $False $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferOptions.OverwriteMode = [WinSCP.OverwriteMode]::Overwrite ## copy file to SFTP $allFiles = -join($filepath,"*") $transferResult = $session.PutFiles($allFiles,$remotePath,$False,$transferOptions); $transferResult.Check(); ##close connection $Session.Close() } finally { # Disconnect, clean up $session.Dispose(); } $FinishedMailParams= @{ To = 'ToEmail' From = 'FromEmail' Port = '' SmtpServer = 'SMTPServer' Subject = 'SUBJECT' Body = "EMAIL BODY" } Send-MailMessage @FinishedMailParams; } catch { ## send email $ErrorMailParams = @{ To = 'ToEmail' From = 'FromEmail' Port = '' SmtpServer = 'SMTPServer' Subject = 'SUBJECT' Body = "Error: $($_.Exception.Message)" } Send-MailMessage @ErrorMailParams; }