Scripted SFTP fails with Cannot Overwrite Remote File

Advertisement

kingeric2510
Joined:
Posts:
3

Scripted SFTP fails with Cannot Overwrite Remote File

I am trying to put files in the remote path,
. 2021-09-29 10:56:01.210 Opening remote file.
> 2021-09-29 10:56:01.210 Type: SSH_FXP_OPEN, Size: 36, Number: 259
< 2021-09-29 10:56:01.225 Type: SSH_FXP_STATUS, Size: 24, Number: 259
< 2021-09-29 10:56:01.225 Status code: 4, Message: 259, Server: Failure, Language:  
> 2021-09-29 10:56:01.225 Type: SSH_FXP_LSTAT, Size: 20, Number: 519
< 2021-09-29 10:56:01.225 Type: SSH_FXP_ATTRS, Size: 37, Number: 519
* 2021-09-29 10:56:01.225 (ETerminal) General failure (server should provide error description).
* 2021-09-29 10:56:01.225 Error code: 4
* 2021-09-29 10:56:01.225 Error message from server: Failure
. 2021-09-29 10:56:01.225 Asking user:
. 2021-09-29 10:56:01.225 Cannot overwrite remote file '/cygdrive/e'.
. 2021-09-29 10:56:01.225  
. 2021-09-29 10:56:01.225 Press 'Delete' to delete the file and create new one instead of overwriting it. ("General failure (server should provide error description).
. 2021-09-29 10:56:01.225 Error code: 4
. 2021-09-29 10:56:01.225 Error message from server: Failure")
< 2021-09-29 10:56:01.225 Script: Cannot overwrite remote file '/cygdrive/e'.
< 2021-09-29 10:56:01.225 Press 'Delete' to delete the file and create new one instead of overwriting it.
< 2021-09-29 10:56:01.241 Script: General failure (server should provide error description).
< 2021-09-29 10:56:01.241 Error code: 4
< 2021-09-29 10:56:01.241 Error message from server: Failure
* 2021-09-29 10:56:01.241 (EScpSkipFile) Cannot overwrite remote file '/cygdrive/e'.
* 2021-09-29 10:56:01.241  
* 2021-09-29 10:56:01.241 Press 'Delete' to delete the file and create new one instead of overwriting it.
* 2021-09-29 10:56:01.241 General failure (server should provide error description).
* 2021-09-29 10:56:01.241 Error code: 4
* 2021-09-29 10:56:01.241 Error message from server: Failure
. 2021-09-29 10:56:01.241 Script: Failed
> 2021-09-29 10:56:01.350 Script: exit
. 2021-09-29 10:56:01.350 Script: Exit code: 1
. 2021-09-29 10:56:01.350 Closing connection.
. 2021-09-29 10:56:01.350 Sending special code: 12
. 2021-09-29 10:56:01.350 Sent EOF message

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,205
Location:
Prague, Czechia

Re: Scripted SFTP fails with Cannot Overwrite Remote File

I assume that /cygdrive/e is a target directory. In such case, you are missing trailing slash. It should be /cygdrive/e/.
See https://winscp.net/eng/docs/library_session_putfiles#remotepath

Or use Session.PutFilesToDirectory:
https://winscp.net/eng/docs/library_session_putfilestodirectory

You also urgently need to upgrade, WinSCP 5.5.5 is over 7 years old.

Reply with quote

kingeric2510
Joined:
Posts:
3

Scripted SFTP fails with Cannot Overwrite Remote File

I change to directory, but same error:
. 2021-09-30 14:24:20.970 WinSCP Version 5.5.5 (Build 4605) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Enterprise)
. 2021-09-30 14:24:20.970 Configuration: nul
. 2021-09-30 14:24:20.970 Local account: IIS APPPOOL\DefaultAppPool
. 2021-09-30 14:24:20.970 Working directory: C:\Program Files (x86)\WinSCP
. 2021-09-30 14:24:20.970 Process ID: 6704
. 2021-09-30 14:24:20.970 Command-line: "C:\Program Files (x86)\WinSCP\winscp.exe" /xmllog="C:\Users\DefaultAppPool\AppData\Local\Temp\wscp0814.01FADA45.tmp" /xmlgroups /nointeractiveinput /dotnet=555  /ini=nul /log="D:\Data\Logs\log_winscp.log"  /console /consoleinstance=_2068_19723548_886
. 2021-09-30 14:24:20.970 Time zone: Current: GMT+7 (SE Asia Standard Time), No DST
. 2021-09-30 14:24:20.970 Login time: Thursday, September 30, 2021 2:24:20 PM
. 2021-09-30 14:24:20.970 --------------------------------------------------------------------------
. 2021-09-30 14:24:20.970 Script: Retrospectively logging previous script records:
> 2021-09-30 14:24:20.970 Script: option batch on
< 2021-09-30 14:24:20.970 Script: batch           on        
> 2021-09-30 14:24:20.970 Script: option confirm off
< 2021-09-30 14:24:20.970 Script: confirm         off       
> 2021-09-30 14:24:20.970 Script: open -hostkey="ssh-rsa 2048 92:f7:d8:77:aa:a0:dd:04:35:76:40:66:5e:42:f8:14" -timeout=15 sftp://cardissue:***@10.4.30.141
. 2021-09-30 14:24:20.970 --------------------------------------------------------------------------
. 2021-09-30 14:24:20.970 Session name: cardissue@10.4.30.141 (Ad-Hoc site)
. 2021-09-30 14:24:20.970 Host name: 10.4.30.141 (Port: 22)
. 2021-09-30 14:24:20.970 User name: cardissue (Password: Yes, Key file: No)
. 2021-09-30 14:24:20.970 Tunnel: No
. 2021-09-30 14:24:20.970 Transfer Protocol: SFTP
. 2021-09-30 14:24:20.970 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2021-09-30 14:24:20.970 Proxy: none
. 2021-09-30 14:24:20.970 Send buffer: 262144
. 2021-09-30 14:24:20.970 SSH protocol version: 2; Compression: No
. 2021-09-30 14:24:20.970 Bypass authentication: No
. 2021-09-30 14:24:20.970 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2021-09-30 14:24:20.970 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2021-09-30 14:24:20.970 SSH Bugs: A,A,A,A,A,A,A,A,A,A
. 2021-09-30 14:24:20.970 Simple channel: Yes
. 2021-09-30 14:24:20.970 Return code variable: Autodetect; Lookup user groups: A
. 2021-09-30 14:24:20.970 Shell: default
. 2021-09-30 14:24:20.970 EOL: 0, UTF: 2
. 2021-09-30 14:24:20.970 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2021-09-30 14:24:20.970 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2021-09-30 14:24:20.970 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2021-09-30 14:24:20.970 Cache directory changes: Yes, Permanent: Yes
. 2021-09-30 14:24:20.970 DST mode: 1; Timezone offset: 0h 0m
. 2021-09-30 14:24:20.970 --------------------------------------------------------------------------
. 2021-09-30 14:24:21.002 Looking up host "10.4.30.141"
. 2021-09-30 14:24:21.002 Connecting to 10.4.30.141 port 22
. 2021-09-30 14:24:21.064 Server version: SSH-2.0-OpenSSH_6.6
. 2021-09-30 14:24:21.064 Using SSH protocol version 2
. 2021-09-30 14:24:21.064 We claim version: SSH-2.0-WinSCP_release_5.5.5
. 2021-09-30 14:24:21.095 Doing Diffie-Hellman group exchange
. 2021-09-30 14:24:21.142 Doing Diffie-Hellman key exchange with hash SHA-256
. 2021-09-30 14:24:21.735 Verifying host key rsa2 0x10001,0xdacbe9285f524f2b 8f9b2a2383fc36e5 6aa72f27b8e4c2d9 0857c07b0bf7a5ee 8ada386aa5386912 590ca37be8f3b583 b2a0ae647cd6d141 78d2486113ccfbdb 8b02abf52ab61be5 a75b1b9b19633f74 d406d207cd2a269b e695992d52ade6e8 f37e94b91f3a62f4 13323c5eb294b1de 4b605a13010c31c5 5856550a192b8e71 c76117548885c341 651ba65f3529e736 4d06b18f2e5a4730 9963d35bd05ca8fb 06b6a863fb9680ea 7ac664a6ab0694b2 408bd0e465e462d9 00bae5c782e4421f cb00f8b50b02b4b2 c780a049542f7631 2affc3c38c71471d 504e01d08c9799cf 777b6dde386a3e90 d21499c89e937dc5 0ebc9dc2c3a7c97d f568274c6db6086b  with fingerprint ssh-rsa 2048 92:f7:d8:77:aa:a0:dd:04:35:76:40:66:5e:42:f8:14
. 2021-09-30 14:24:21.735 Host key matches configured key
. 2021-09-30 14:24:21.735 Host key fingerprint is:
. 2021-09-30 14:24:21.735 ssh-rsa 2048 92:f7:d8:77:aa:a0:dd:04:35:76:40:66:5e:42:f8:14
. 2021-09-30 14:24:21.735 Initialised AES-256 SDCTR client->server encryption
. 2021-09-30 14:24:21.735 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2021-09-30 14:24:21.735 Initialised AES-256 SDCTR server->client encryption
. 2021-09-30 14:24:21.735 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2021-09-30 14:24:21.782 Using username "cardissue".
. 2021-09-30 14:24:33.794 Attempting keyboard-interactive authentication
. 2021-09-30 14:24:33.794 Server refused keyboard-interactive authentication
. 2021-09-30 14:24:33.794 Prompt (7, SSH password, , &Password: )
. 2021-09-30 14:24:33.794 Using stored password.
. 2021-09-30 14:24:33.794 Sent password
. 2021-09-30 14:24:33.825 Access granted
. 2021-09-30 14:24:33.825 Opening session as main channel
. 2021-09-30 14:24:33.825 Opened main channel
. 2021-09-30 14:24:33.872 Started a shell/command
. 2021-09-30 14:24:33.872 --------------------------------------------------------------------------
. 2021-09-30 14:24:33.872 Using SFTP protocol.
. 2021-09-30 14:24:33.872 Doing startup conversation with host.
> 2021-09-30 14:24:33.872 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2021-09-30 14:24:33.887 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2021-09-30 14:24:33.887 SFTP version 3 negotiated.
. 2021-09-30 14:24:33.887 Unknown server extension posix-rename@openssh.com="1"
. 2021-09-30 14:24:33.887 Supports statvfs@openssh.com extension version "2"
. 2021-09-30 14:24:33.887 Unknown server extension fstatvfs@openssh.com="2"
. 2021-09-30 14:24:33.887 Unknown server extension hardlink@openssh.com="1"
. 2021-09-30 14:24:33.887 Unknown server extension fsync@openssh.com="1"
. 2021-09-30 14:24:33.887 We believe the server has signed timestamps bug
. 2021-09-30 14:24:33.887 We will use UTF-8 strings when appropriate
. 2021-09-30 14:24:33.887 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2021-09-30 14:24:33.887 Getting current directory name.
. 2021-09-30 14:24:33.887 Getting real path for '.'
> 2021-09-30 14:24:33.887 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2021-09-30 14:24:33.903 Type: SSH_FXP_NAME, Size: 83, Number: 16
. 2021-09-30 14:24:33.903 Real path is '/cygdrive/e/embossing_file/vccs'
. 2021-09-30 14:24:33.903 Startup conversation with host finished.
< 2021-09-30 14:24:33.903 Script: Active session: [1] cardissue@10.4.30.141
> 2021-09-30 14:24:34.277 Script: put  -nopermissions -preservetime -transfer="binary" -resumesupport="off" -- "D:\CardApp\CardWebSite\func\perso\DC_FILE\DC_outputcards_Chuyen_doi_CTL_moi_VCCS_T51_20210930_093048_" "/cygdrive/d/CARDDATA/VCCS"
. 2021-09-30 14:24:34.277 Copying 1 files/directories to remote directory "/cygdrive/d/CARDDATA/"
. 2021-09-30 14:24:34.277   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: N (102400); CalcS: No; Mask: VCCS
. 2021-09-30 14:24:34.277   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: 
. 2021-09-30 14:24:34.277   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2021-09-30 14:24:34.277 File: 'D:\CardApp\CardWebSite\func\perso\DC_FILE\DC_outputcards_Chuyen_doi_CTL_moi_VCCS_T51_20210930_093048_' [2021-09-30T02:45:07.243Z] [32580]
. 2021-09-30 14:24:34.277 Copying "D:\CardApp\CardWebSite\func\perso\DC_FILE\DC_outputcards_Chuyen_doi_CTL_moi_VCCS_T51_20210930_093048_" to remote directory started.
. 2021-09-30 14:24:34.277 Binary transfer mode selected.
. 2021-09-30 14:24:34.277 Opening remote file.
> 2021-09-30 14:24:34.277 Type: SSH_FXP_OPEN, Size: 50, Number: 259
< 2021-09-30 14:24:34.293 Type: SSH_FXP_STATUS, Size: 24, Number: 259
< 2021-09-30 14:24:34.293 Status code: 4, Message: 259, Server: Failure, Language:  
> 2021-09-30 14:24:34.293 Type: SSH_FXP_LSTAT, Size: 34, Number: 519
< 2021-09-30 14:24:34.309 Type: SSH_FXP_ATTRS, Size: 37, Number: 519
* 2021-09-30 14:24:34.309 (ETerminal) General failure (server should provide error description).
* 2021-09-30 14:24:34.309 Error code: 4
* 2021-09-30 14:24:34.309 Error message from server: Failure
. 2021-09-30 14:24:34.309 Asking user:
. 2021-09-30 14:24:34.309 Cannot overwrite remote file '/cygdrive/d/CARDDATA/VCCS'.
. 2021-09-30 14:24:34.309  
. 2021-09-30 14:24:34.309 Press 'Delete' to delete the file and create new one instead of overwriting it. ("General failure (server should provide error description).
. 2021-09-30 14:24:34.309 Error code: 4
. 2021-09-30 14:24:34.309 Error message from server: Failure")
< 2021-09-30 14:24:34.309 Script: Cannot overwrite remote file '/cygdrive/d/CARDDATA/VCCS'.
< 2021-09-30 14:24:34.309 Press 'Delete' to delete the file and create new one instead of overwriting it.
< 2021-09-30 14:24:34.309 Script: General failure (server should provide error description).
< 2021-09-30 14:24:34.309 Error code: 4
< 2021-09-30 14:24:34.309 Error message from server: Failure
* 2021-09-30 14:24:34.309 (EScpSkipFile) Cannot overwrite remote file '/cygdrive/d/CARDDATA/VCCS'.
* 2021-09-30 14:24:34.309  
* 2021-09-30 14:24:34.309 Press 'Delete' to delete the file and create new one instead of overwriting it.
* 2021-09-30 14:24:34.309 General failure (server should provide error description).
* 2021-09-30 14:24:34.309 Error code: 4
* 2021-09-30 14:24:34.309 Error message from server: Failure
. 2021-09-30 14:24:34.309 Script: Failed
> 2021-09-30 14:24:34.433 Script: exit
. 2021-09-30 14:24:34.433 Script: Exit code: 1
. 2021-09-30 14:24:34.433 Closing connection.
. 2021-09-30 14:24:34.433 Sending special code: 12
. 2021-09-30 14:24:34.433 Sent EOF message
Is my code :
SessionOptions sessionOptions = new SessionOptions();
 
sessionOptions.Protocol = Protocol.sftp;
sessionOptions.HostName = "****";
sessionOptions.UserName = "****";
sessionOptions.Password = "****";
sessionOptions.SshHostKeyFingerprint = "****";
 
using (Session session = new Session())
{
    session.DebugLogPath = "D:\\Data\\Logs\\DebugLog_winscp.log";
    session.SessionLogPath = "D:\\Data\\Logs\\log_winscp.log";
    session.Open(sessionOptions); //Attempts to connect to your sFtp site
    //Get Ftp File
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode - 
    TransferOperationResult transferResult;
    transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
    transferResult = session.PutFiles(localPathWithFilename, "/cygdrive/e/EMBOSSING_FILE/VCCS", false, transferOptions);
    //Throw on any error 
    transferResult.Check();

Reply with quote

martin
Site Admin
martin avatar

Re: Scripted SFTP fails with Cannot Overwrite Remote File

Because your code still seems to have the same issue. If the /cygdrive/e/EMBOSSING_FILE/VCCS is a folder, there must be a slash at the end.

Reply with quote

Advertisement

You can post new topics in this forum