Get 226 Responses after Session.PutFiles

Advertisement

abillon
Joined:
Posts:
11
Location:
France

Get 226 Responses after Session.PutFiles

Hello,

I am working on a Powershell Script that sends files to a FTPS server.
I would like to be able to extract the 226 responses of the server after the put or the 250 responses after a move.

I was hoping on a Output property on the TransferEventArgs objects but it doesn't exist.
No luck either with the OutputDataReceived events

Is there a way ?

...
> 2018-01-22 10:08:13.233 Script: put -nopermissions -preservetime -transfer="binary" -- "C:\path\to\send\3.pdf" "/3.pdf.tmp"
. 2018-01-22 10:08:13.233 Copying 1 files/directories to remote directory "/"
. 2018-01-22 10:08:13.233 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: 3.pdf.tmp
. 2018-01-22 10:08:13.233 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2018-01-22 10:08:13.233 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2018-01-22 10:08:13.233 File: 'C:\path\to\send\3.pdf' [2018-01-05T16:48:26.257Z] [641406]
. 2018-01-22 10:08:13.233 Copying "C:\path\to\send\3.pdf" to remote directory started.
. 2018-01-22 10:08:13.243 Binary transfer mode selected.
. 2018-01-22 10:08:13.243 Starting upload of C:\path\to\send\3.pdf
> 2018-01-22 10:08:13.243 TYPE I
< 2018-01-22 10:08:13.273 200 TYPE changed to I.
> 2018-01-22 10:08:13.273 PASV
< 2018-01-22 10:08:13.313 227 Entering Passive Mode (193,188,249,232,195,196)
> 2018-01-22 10:08:13.313 STOR 3.pdf.tmp
. 2018-01-22 10:08:13.313 Connecting to 193.188.249.232:50116 ...
< 2018-01-22 10:08:13.343 150 Opening BINARY mode data connection for file 3.pdf.tmp.
. 2018-01-22 10:08:13.653 Using TLSv1, cipher TLSv1/SSLv3: DHE-RSA-AES256-SHA, 2048 bit RSA, DHE-RSA-AES256-SHA SSLv3 Kx=DH Au=RSA Enc=AES(256) Mac=SHA1
. 2018-01-22 10:08:13.653 TLS connection established
< 2018-01-22 10:08:15.513 226 Temporary file 3.pdf.tmp received, rename to send
> 2018-01-22 10:08:15.513 MDTM 20180105164826 3.pdf.tmp
< 2018-01-22 10:08:15.540 550 File or directory not found.
. 2018-01-22 10:08:15.540 Upload successful
. 2018-01-22 10:08:15.546 Transfer done: 'C:\path\to\send\3.pdf' [641406]
> 2018-01-22 10:08:15.666 Script: mv "/3.pdf.tmp" "3.pdf"
. 2018-01-22 10:08:15.667 Moving file "/3.pdf.tmp" to "3.pdf".
> 2018-01-22 10:08:15.667 RNFR /3.pdf.tmp
< 2018-01-22 10:08:15.694 350 OK. Send RNTO command to complete rename operation.
> 2018-01-22 10:08:15.695 RNTO /3.pdf
< 2018-01-22 10:08:15.725 250 MSG 1248449327/1 ABC/DEF999 (******) -> FAX/+33-9********/LOGO=BLANK, ATTN ********, DACK
...

# Load WinSCP .NET assembly
Add-Type -Path "C:\path\to\WinSCPnet.dll"
 
function FileTransferProgress {
    param($e)
 
    Write-Progress `
        -Activity "Transfer" -Status ("{0:P0} complete:" -f $e.OverallProgress) `
        -PercentComplete ($e.OverallProgress * 100)
    Write-Progress `
        -Id 1 -Activity $e.FileName -Status ("{0:P0} complete:" -f $e.FileProgress) `
        -PercentComplete ($e.FileProgress * 100)
}

try {
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::FTP
   
        FtpSecure = [WinSCP.FtpSecure]::Explicit
        TlsHostCertificateFingerprint = "TlsHostCertificateFingerprint"
        HostName = "HostName"
        UserName = "UserName"
        Password = "Password"

      }
 
    $session = New-Object WinSCP.Session
    try {
        # Will continuously report progress of transfer
        $session.add_FileTransferProgress( { FileTransferProgress($_) } )
        
        
        # Connect
        $session.SessionLogPath = "C:\path\to\log\logging.log"
        $session.Open($sessionOptions)
 
        
        $numFax = "site dest FAX/+33-9********/LOGO=BLANK, ATTN ********, DACK"
        
        $numFaxResult = $session.ExecuteCommand($numFax)
        $numFaxResult.Check()
        $numFaxResult.Output
        
        
        $reference = "site ref TEST{0:yyyyMMddhhmmssffff}" -f [datetime]::Now
        
        $referenceResult = $session.ExecuteCommand($reference)
        $referenceResult.Check()
        $referenceResult.Output
        
        
        $putResult = $session.PutFiles("C:\path\to\send\3.pdf", "/3.pdf.tmp", $false)
        $putResult.Check()
        
        
        $session.MoveFile("/3.pdf.tmp", "3.pdf")
    }
    finally {
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch {
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Thanks for your help

Alex

Reply with quote

Advertisement

abillon
Joined:
Posts:
11
Location:
France

Hello,

Is it something that could be added in the future ?

There is a Output property in CommandExecutionResult that allows to get the 2xx response from the server which is handy.

Reply with quote

Advertisement

You can post new topics in this forum