Issues with WinSCP PUT -delete option

Advertisement

kumar.kk
Joined:
Posts:
3

Issues with WinSCP PUT -delete option

Hi,

I have the below script to transfer files to remote server(Unix) and then delete the files in the local directory. But once in a day we are seeing the below error.
Script: System Error. Code: 2.
The system cannot find the file specified
1 out of 100 files was not copied to the remote directory and is also being deleted from the local folder. Can someone please help me to know if there is a way to NOT delete the file if it was not transferred to the remote server.

We are using WinSCP Version 5.1.7(Build 3446)

Here is the batch script that runs every one minute.
@echo off
start winscp /console /script="C:\CDI\SFTP.txt" /log=SFTP.Log
SFTP.txt:
option batch abort
option confirm off 
open sftp://user:password@HostName -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:x:xx:xx:xx"
lcd C:\input\
cd inbound
option transfer binary
put -delete File_20141214230801099.txt
chmod 777 File_20141214230801099.txt
close
exit
Thanks
Kumar
  • LogFile.txt (7.67 KB, Private file)
Description: Log File attached

Reply with quote

Advertisement

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

Re: Issues with Winscp PUT -Delete option

WinSCP does not delete the local file, if the upload fails.
So I actually believe the file did not exist already at the time the upload started, hence the error message.

Reply with quote

kumar.kk

Issues with Winscp PUT -Delete option

Thanks for the reply prikryl. we even tried to trigger the script only when the file is present in folder. we have this issue for only 1 or 2 files a day. Is there any other way to transfer files to remote server and delete the local files using batch script.

Reply with quote

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

Re: Issues with Winscp PUT -Delete option

kumar.kk wrote:

we even tried to trigger the script only when the file is present in folder.
How do your check that?
Isn't there any other process that might delete the file, after you test file existence, but before you run WinSCP?

Is there any other way to transfer files to remote server and delete the local files using batch script.
Your code is correct, there's nothing to be done differently.

Reply with quote

kumar.kk

Issues with Winscp PUT -Delete option

There is no other process to delete the file in the local directory except the SFTP script which has put -delete option.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Issues with Winscp PUT -Delete option

I have sent you an email with a debug version of WinSCP to address you have used to register on this forum.

Reply with quote

matrixtan
Guest

How to delete all files in the folder located on a SFTP site using Excel VBA?

What is the code to use?
My folder is name is SCB.

Reply with quote

Sathish Kumar
Guest

Files are missing while transferring to two different folders.

Hi Martin,

I am using the WinSCP PowerShell script to move the files in two different folders from local directory.

We are receiving PDF and XML files at the same time to our local machine. We need to send both XML and PDF in one remote directory and the same PDF only we need to move into another remote directory.

For that I wrote the below script. But anyhow we are receiving many files are missing in the folder which we are using for transfer only the PDF.

MY Script:
param (
    $backupPath = "D:\Backup\occ_archive\"
)
try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "tardis-sftp.pinternal.net"
        UserName = "muraai"
        SshHostKeyFingerprint = "ssh-rsa 2048 bO+fomFyD2OdtOZ6AJPQu1JRWh3LZQTpv/WPEUinLP0="
        SshPrivateKeyPath = "D:\Software\SSH-Key\occ_prod.ppk"
    }
 
    $session = New-Object WinSCP.Session
    try
    {
        $Session.SessionLogPath = "D:\Log\log2.log"
        # Connect
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions -Property @{
            PreserveTimestamp = $False
            ResumeSupport = New-Object WinSCP.TransferResumeSupport -Property @{ State = [WinSCP.TransferResumeSupportState]::Off }
        }
         
        $transferResult =
            $session.PutFiles("D:\OCC\XML_PROD\*.pdf", "/pinit-sftp-tardis/muraai/occ_prod/oracle_pdf/", $False, $transferOptions) 
 
        $transferResult1 =
            $session.PutFiles("D:\OCC\XML_PROD\*\", "/pinit-sftp-tardis/muraai/occ_prod/", $False, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
        $transferResult1.Check()                     
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host "Upload of $($transfer.FileName) succeeded"
            Copy-Item $transfer.FileName $backupPath
            Write-Host "Copy of $($transfer.FileName) completed"
        }
        foreach ($transfer1 in $transferResult1.Transfers)
        {
            Write-Host "Upload of $($transfer1.FileName) succeeded"
            Remove-Item $transfer1.FileName
            Write-Host "Deletion of $($transfer1.FileName) completed"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

Reply with quote

Advertisement

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

Re: Files are missing while transferring to two different folders.

@SathishKumar: First, this is completelly different problem than what this topic is about. Please start a new thread and make sure you include complete session log files documenting the problem. And give us a name of a some file that was not uploaded.

Btw, this is definitelly wrong: D:\OCC\XML_PROD\*\. The trailing backslash should not be there.

Reply with quote

Advertisement

You can post new topics in this forum