Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Burtamus

RESOLVED!

The issue was the remote path. Instead of just using /, the server was looking for ftp://<user>@<server>. This can be found in the GUI under Session/Generate Session URL.
martin

For the Enable transfer resume/transfer to temporary filename for option, choose Disable.

Your code already does that.

For Transfer, choose Background, and clear the Use multiple connections for single transfer check box

This is irrelevant for the .NET assembly, as it never uses multiple connections on its own.

So your problem must be elsewhere. Please post session log file from WinSCP GUI showing a successful upload.
Burtamus

This is the script I'm using to do the upload...
try {
    # Load WinSCP .NET assembly
    Add-Type -Path ".\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "sftp.*****.com"
        UserName = "*****"
        SshHostKeyFingerprint = "ssh-rsa 2048 *****"
        SshPrivateKeyPath = "D:\Source\*****.ppk"
    }
 
    $session = New-Object WinSCP.Session
 
    try {
        # Connect
        $session.SessionLogPath = ".\$($Filename).log"
        $session.Open($sessionOptions)
 
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::ASCII
        $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
 
        $transferResult = $session.PutFiles($FileName, "/", $False, $transferOptions).Check()
    }
    finally {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch {
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}
Burtamus

Log file attached.
Burtamus

Sorry, I did not tell anyone that. It was told to me that the SFTP host required it set that way. I'll say again that the GUI works perfectly fine for uploading, it is just the command line that is having this issue.

Is there no documentation on how to set those options via the command line? It took me a week, but I finally found a way to log to a file. I'll work at getting that uploaded. Documentation on the command line is sadly lacking.
Thanks, Burt
martin

Re: PowerShell options

Who did you tell that? Why do you think these options are relevant?

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
Burtamus

PowerShell options

I'm trying to write a PowerShell Script to upload a newly created file. When I attempt to do so, it says...
Error: Exception calling "Check" with "0" argument(s): "Cannot overwrite remote file '/<filename>.ldif'.$$

Press 'Delete' to delete the file and create new one instead of overwriting it.$$
No such file or directory.
Error code: 2
Error message from server (US-ASCII): /<filename>.ldif"

I've been told to do two things...

  • For the Enable transfer resume/transfer to temporary filename for option, choose Disable.
  • For Transfer, choose Background, and clear the Use multiple connections for single transfer check box.

Easy enough in the GUI (BTW, the GUI works fine, not the PowerShell tho). How do I set these options in PowerShell? Examples greatly appreciated.