Winscp c# assembly Script: Error deleting file '<Path>' while getfiles

Advertisement

Femil Shajin
Guest

Winscp c# assembly Script: Error deleting file '<Path>' while getfiles

This is my script in c# to getfiles and delete from sftp, When I connect through filezilla I can delete files. but when I run the script the log file says permission denied.

C# Script
SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    PortNumber = 22,
                    HostName = sftpHost,
                    UserName = sftpUsername,
                    Password = sftpPassword,
                    SshHostKeyFingerprint = sshHostKeyFingerprint,
                    SshPrivateKeyPath = @"E:\Femil\SFTPSample\SFTPSample\CKV022_PVT.ppk",
                    TimeoutInMilliseconds = 90000,
                };

                using (Session session = new Session())
                {
                    session.SessionLogPath = logPath+"\\log.txt";
                    session.Open(sessionOptions); //Attempts to connect to your sFtp site
                    //Get Ftp File
                    TransferOptions transferOptions = new TransferOptions(); 
                    transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode - Automatic, Binary, or Ascii 
                    transferOptions.FilePermissions = null;  //Permissions applied to remote files; 
                    //<em style="font-size: 9pt;">null for default permissions.  
                    //Can set <em style="font-size: 9pt;">user, Group, or other Read/Write/Execute permissions.  
                    transferOptions.PreserveTimestamp = false;  //Set last write time of destination file 
                    //to that of source file - basically change the timestamp to match destination and source files.    
                    transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;

                    TransferOperationResult transferResult;
                    //the parameter list is: remote Path, Local Path with filename 
                    //(optional - if different from remote path), Delete source file?, transfer Options  
                    transferResult = session.GetFiles("/" + remotePath, localPath, false, transferOptions); 
                    //Throw on any error 
                    transferResult.Check(); 
                    //Log information and break out if necessary  

                    // Print results
                    foreach (TransferEventArgs transfer in transferResult.Transfers)
                    {
                        Console.WriteLine("Download of {0} succeeded", transfer.FileName);
                        WriteLog("Download of " + transfer.FileName + " succeeded");
                    }
            }

Log File
< 2015-08-27 22:03:45.101 Script: Error deleting file '<Path>'.
< 2015-08-27 22:03:45.101 Script: Permission denied.
< 2015-08-27 22:03:45.101 Error code: 3
< 2015-08-27 22:03:45.101 Error message from server (en): Permission denied
. 2015-08-27 22:03:45.101 Script: Failed
> 2015-08-27 22:03:45.180 Script: exit
. 2015-08-27 22:03:45.180 Script: Exit code: 1
. 2015-08-27 22:03:45.180 Closing connection.
. 2015-08-27 22:03:45.180 Sending special code: 12
. 2015-08-27 22:03:45.180 Sent EOF message

Reply with quote

Advertisement

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

Re: Winscp c# assembly Script: Error deleting file '<Path>' while getfiles

There's no call to deleting files in your code.

Can you attach a full non-obfuscated log?

Can you delete the file in WinSCP GUI?

Reply with quote

Advertisement

You can post new topics in this forum