Error Code 0 Special Code 12 ... Resume?

Advertisement

wos
Joined:
Posts:
2

Error Code 0 Special Code 12 ... Resume?

Hi,

a script, which should send some files to a server and (if successful) move them to a "done" location, seems to work (Error Code 0) but has also a problem (Sending special code: 12) and in fact ... it doesn't work.

Since I've read some posts here and part of the documentation, I was able to solve most of my issues, but now I'm completely stuck! I think my remaining problem has something to do with the "resume" ability ...

... 
2016-01-25 16:43:05.289 Sent public key signature
2016-01-25 16:43:05.321 Access granted
2016-01-25 16:43:05.321 Opening session as main channel
2016-01-25 16:43:05.336 Opened main channel
2016-01-25 16:43:05.368 Started a shell/command
2016-01-25 16:43:05.368 --------------------------------------------------------------------------
2016-01-25 16:43:05.368 Using SFTP protocol.
2016-01-25 16:43:05.368 Doing startup conversation with host.
2016-01-25 16:43:05.368 Type: SSH_FXP_INIT, Size: 5, Number: -1
2016-01-25 16:43:05.383 Type: SSH_FXP_VERSION, Size: 150, Number: -1
2016-01-25 16:43:05.383 SFTP version 3 negotiated.
2016-01-25 16:43:05.383 Unknown server extension posix-rename@openssh.com="1"
2016-01-25 16:43:05.383 Supports statvfs@openssh.com extension version "2"
2016-01-25 16:43:05.383 Unknown server extension fstatvfs@openssh.com="2"
2016-01-25 16:43:05.383 Supports hardlink@openssh.com extension version "1"
2016-01-25 16:43:05.383 Unknown server extension fsync@openssh.com="1"
2016-01-25 16:43:05.383 We believe the server has signed timestamps bug
2016-01-25 16:43:05.383 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 string are not mandatory
2016-01-25 16:43:05.383 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
2016-01-25 16:43:05.383 Getting current directory name.
2016-01-25 16:43:05.383 Getting real path for '.'
2016-01-25 16:43:05.383 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
2016-01-25 16:43:05.399 Type: SSH_FXP_NAME, Size: 23, Number: 16
2016-01-25 16:43:05.399 Real path is '/'
2016-01-25 16:43:05.399 Startup conversation with host finished.
2016-01-25 16:43:05.399 Script: Aktive Sitzung: [1] someone@123.123.123.123
2016-01-25 16:43:05.664 Script: pwd
2016-01-25 16:43:05.664 Script: /
2016-01-25 16:43:05.821 Script: put  -nopermissions -preservetime -transfer="binary" -- "C:\Irgendwas\*" "/in/"
2016-01-25 16:43:05.821 Copying 1 files/directories to remote directory "/in/"
2016-01-25 16:43:05.821   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: 
2016-01-25 16:43:05.821   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
2016-01-25 16:43:05.821   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
2016-01-25 16:43:05.821 File: 'C:\Irgendwas\GanzGanzNeu.txt' [2016-01-25T14:14:20.066Z] [5]
2016-01-25 16:43:05.821 Copying "C:\Irgendwas\GanzGanzNeu.txt" to remote directory started.
2016-01-25 16:43:05.821 Binary transfer mode selected.
2016-01-25 16:43:05.821 Opening remote file.
2016-01-25 16:43:05.821 Type: SSH_FXP_OPEN, Size: 44, Number: 259
2016-01-25 16:43:05.836 Type: SSH_FXP_HANDLE, Size: 13, Number: 259
2016-01-25 16:43:05.836 Type: SSH_FXP_WRITE, Size: 30, Number: 774
2016-01-25 16:43:05.836 Type: SSH_FXP_CLOSE, Size: 13, Number: 1028
2016-01-25 16:43:05.836 Type: SSH_FXP_SETSTAT, Size: 40, Number: 521
2016-01-25 16:43:05.852 Type: SSH_FXP_STATUS, Size: 24, Number: 774
2016-01-25 16:43:05.868 Type: SSH_FXP_STATUS, Size: 24, Number: 1028
2016-01-25 16:43:05.868 Status code: 0
2016-01-25 16:43:05.868 Preserving timestamp [2016-01-25T14:14:20.000Z]
2016-01-25 16:43:05.868 Type: SSH_FXP_STATUS, Size: 24, Number: 521
2016-01-25 16:43:05.868 Status code: 0
2016-01-25 16:43:05.868 Transfer done: 'C:\Irgendwas\GanzGanzNeu.txt' [5]
2016-01-25 16:43:06.071 Script: exit
2016-01-25 16:43:06.071 Script: Exit code: 0
2016-01-25 16:43:06.071 Closing connection.
2016-01-25 16:43:06.071 Sending special code: 12
2016-01-25 16:43:06.071 Sent EOF message

... and I just want to turn it off! But I dont know, if I implemented the commands correctly which I've from the dokumentation. And if it was right ... whats the reason, that my uploaded file is afterwards not there? If i use the GUI, all is working nice. If I read the logs, it seemed to be nice. Here's what I've done in the according script (special interest in the transfer resume options):

param (
    $localPath = "C:\SourceFiles\*",
    $remotePath = "/in/",
    $backupPath = "C:\TransferedFiles\"
)
 
try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "194.138.20.139"
    $sessionOptions.UserName = "SomeOne"
    # PASSWORT WIRD NICHT GEBRAUCHT
    # $sessionOptions.Password = ""
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
    $sessionOptions.SshPrivateKeyPath = "C:\Program Files (x86)\WinSCP\SomeOnePrivateKey.ppk"
 
    $session = New-Object WinSCP.Session

    # UM LOG ZU ERZEUGEN DARF FOLGENDE ZEILE NICHT AUSGEREMT SEIN
    $session.SessionLogPath = "C:\Program Files (x86)\WinSCP\Logs\Log.txt"
 
    try
    {
        # Connect
        $session.Open($sessionOptions)

        # ResumeMode Off
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        # Upload files, collect results
        $transferResult = $session.PutFiles($localPath, $remotePath)
 
        # Iterate over every transfer
        foreach ($transfer in $transferResult.Transfers)
        {
            # Success or error?
            if ($transfer.Error -eq $Null)
            {
                Write-Host ("Upload of {0} succeeded, moving to backup" -f
                    $transfer.FileName)
                # Upload succeeded, move source file to backup
                Move-Item $transfer.FileName $backupPath
            }
            else
            {
                Write-Host ("Upload of {0} failed: {1}" -f
                    $transfer.FileName, $transfer.Error.Message)
            }
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception.Message
    exit 1
}

Does anebody has a clue whats wrong with my script ... or why its telling me: It has copied all and then the files are not there? The Backup Part is working ... just the transfer to the sftp is my problem!

Thx a lot

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Error Code 0 Special Code 12 ... Resume?

Can you see the file in the /in/ folder, when you upload it using any GUI SFTP client?

Reply with quote

wos
Joined:
Posts:
2

Hi Prikryl,

thx for your response, I was a bit away, but here's the answer:

Can you see the file in the /in/ folder, when you upload it using any GUI SFTP client?

Yes. If i connect manually with the GUI, navigate into the /in/ folder and upload the File (F5) it's working as supposed. Am I right with my suspect, that this could be a resume problem and how to supress the resume mechanism?

Have a nice Weekend

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

It's not related to resuming probably.

Add Session.ListDirectory call to the PowerShell script, enable logging and attach the log.
And attach a log showing the GUI upload.

Reply with quote

Advertisement

You can post new topics in this forum