Keep getting Cannot overwrite remote file

Advertisement

Swindellvc@cofc.edu
Joined:
Posts:
12
Location:
Charleston, SC

Keep getting Cannot overwrite remote file

I have a vb.net program that I wrote to upload Student Photos that have been added in the last 14 days to a remote site, It keeps crashing with:
Cannot overwrite remote file <name> of file.
And I'm trying to find a work around.

code:
Dim mySessionOptions As New WinSCP.SessionOptions
    Dim PicCount As Integer = 0
    Static start_time As DateTime
    Static stop_time As DateTime
    Dim elapsed_time As TimeSpan
    Dim TOinterval As New TimeSpan(0, 30, 0)
    Dim transferResult As TransferOperationResult
    Dim MyTransferOptions As New WinSCP.TransferOptions
 
    start_time = Now
    mySession.DisableVersionCheck = False
    With mySessionOptions
        .Protocol = Protocol.Sftp
        .PortNumber = 22
        .HostName = "<site name>"
        .PrivateKeyPassphrase = classified
        .UserName = "cofc"
        .SshHostKeyFingerprint = <key>
        .SshPrivateKeyPath = "\\aiken\ProdCognos\ITExtracts\SSHKEY\myKey.ppk"
        .PrivateKeyPassphrase = <Phrase>
        .Timeout = New TimeSpan(0, 4, 30)
        .AddRawSettings("ConsiderDST", "0")
    End With
 
    'Connect
    mySession.Open(mySessionOptions)
 
    'Upload files        
    With MyTransferOptions
        .TransferMode = TransferMode.Automatic
        .FileMask = "*>=14D"  'Transfer only files changed in the last 14 days
        .ResumeSupport.State = TransferResumeSupportState.Smart
        .PreserveTimestamp = False
        .OverwriteMode = OverwriteMode.Resume
    End With
 
    transferResult = mySession.PutFiles("\\aiken\IDPhotos\*.jpg", "/studentpics/", False, MyTransferOptions)
 
    'Throw on any error
    Try
        transferResult.Check()
    Catch ex As System.IO.IOException
        Console.WriteLine(ex.Message)
    End Try
 
    Dim transfer As TransferEventArgs
    For Each transfer In transferResult.Transfers
        Console.WriteLine("Upload of {0} succeeded" & vbCrLf, transfer.FileName)
        PicCount = PicCount + 1
    Next
 
    stop_time = Now
    elapsed_time = stop_time.Subtract(start_time)
 
    sMsg = sMsg & "A total of " & PicCount & " images  have been uploaded." & vbCrLf
    sMsg = sMsg & "Total elapsed time " & elapsed_time.TotalMinutes.ToString("0.000000") & " minutes."

Reply with quote E-mail

Advertisement

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

Re: Keep getting Cannot overwrite remote file

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Swindellvc@cofc.edu
Joined:
Posts:
12
Location:
Charleston, SC

Log file

. 2020-12-18 09:52:18.454 --------------------------------------------------------------------------
. 2020-12-18 09:52:18.455 WinSCP Version 5.17.6 (Build 10516) (OS 10.0.17134 - Windows 10 Enterprise)
. 2020-12-18 09:52:18.455 Configuration: nul
. 2020-12-18 09:52:18.456 Log level: Normal
. 2020-12-18 09:52:18.457 Local account: COUGARS\REDACTED
. 2020-12-18 09:52:18.458 Working directory: C:\Program Files (x86)\WinSCP
. 2020-12-18 09:52:18.459 Process ID: 3444
. 2020-12-18 09:52:18.460 Command-line: "C:\Program Files (x86)\WinSCP\winscp.exe" /xmllog="C:\Users\Swindellvc\AppData\Local\Temp\wscp4B84.023404EE.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=5.17.6  /ini=nul /log="\\aiken\ProdItFileTrans\FILES\LOGS\PicsFileTrans.log"  /console /consoleinstance=_19332_25474675_795
. 2020-12-18 09:52:18.461 Time zone: Current: GMT-5, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/8/2020, DST End: 11/1/2020
. 2020-12-18 09:52:18.462 Login time: Friday, December 18, 2020 9:52:18 AM
. 2020-12-18 09:52:18.462 --------------------------------------------------------------------------
. 2020-12-18 09:52:18.463 Script: Retrospectively logging previous script records:
> 2020-12-18 09:52:18.464 Script: option batch on
< 2020-12-18 09:52:18.464 Script: batch           on        
< 2020-12-18 09:52:18.465 Script: reconnecttime   120       
> 2020-12-18 09:52:18.465 Script: option confirm off
< 2020-12-18 09:52:18.466 Script: confirm         off       
> 2020-12-18 09:52:18.466 Script: option reconnecttime 120
< 2020-12-18 09:52:18.467 Script: reconnecttime   120       
> 2020-12-18 09:52:18.467 Script: open sftp://cofc@sftp.us.erezlife.com:22 -hostkey="REDACTED" -privatekey="\\aiken\ProdCognos\ITExtracts\SSHKEY\myKey.ppk" -timeout=270 -passphrase=*** -rawsettings ConsiderDST="0"
. 2020-12-18 09:52:18.468 --------------------------------------------------------------------------
. 2020-12-18 09:52:18.468 Session name: cofc@sftp.us.erezlife.com (Ad-Hoc site)
. 2020-12-18 09:52:18.469 Host name: sftp.us.erezlife.com (Port: 22)
. 2020-12-18 09:52:18.470 User name: cofc (Password: No, Key file: Yes, Passphrase: Yes)
. 2020-12-18 09:52:18.470 Tunnel: No
. 2020-12-18 09:52:18.470 Transfer Protocol: SFTP
. 2020-12-18 09:52:18.471 Ping type: Off, Ping interval: 30 sec; Timeout: 270 sec
. 2020-12-18 09:52:18.471 Disable Nagle: No
. 2020-12-18 09:52:18.472 Proxy: None
. 2020-12-18 09:52:18.472 Send buffer: 262144
. 2020-12-18 09:52:18.473 SSH protocol version: 2; Compression: No
. 2020-12-18 09:52:18.474 Bypass authentication: No
. 2020-12-18 09:52:18.474 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2020-12-18 09:52:18.474 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2020-12-18 09:52:18.475 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2020-12-18 09:52:18.475 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2020-12-18 09:52:18.476 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2020-12-18 09:52:18.476 Simple channel: Yes
. 2020-12-18 09:52:18.477 Return code variable: Autodetect; Lookup user groups: Auto
. 2020-12-18 09:52:18.477 Shell: default
. 2020-12-18 09:52:18.478 EOL: LF, UTF: Auto
. 2020-12-18 09:52:18.478 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2020-12-18 09:52:18.479 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2020-12-18 09:52:18.479 SFTP Bugs: Auto,Auto
. 2020-12-18 09:52:18.480 SFTP Server: default
. 2020-12-18 09:52:18.480 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2020-12-18 09:52:18.481 Cache directory changes: Yes, Permanent: Yes
. 2020-12-18 09:52:18.481 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2020-12-18 09:52:18.482 DST mode: Win
. 2020-12-18 09:52:18.482 --------------------------------------------------------------------------
. 2020-12-18 09:52:18.484 Looking up host "sftp.us.erezlife.com" for SSH connection
. 2020-12-18 09:52:18.494 Connecting to 54.81.68.171 port 22
. 2020-12-18 09:52:18.570 We claim version: SSH-2.0-WinSCP_release_5.17.6
. 2020-12-18 09:52:18.571 Remote version: SSH-2.0-OpenSSH_7.4
. 2020-12-18 09:52:18.571 Using SSH protocol version 2
. 2020-12-18 09:52:18.572 Have a known host key of type ssh-ed25519
. 2020-12-18 09:52:18.597 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2020-12-18 09:52:18.740 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2020-12-18 09:52:18.741 Host key fingerprint is:
. 2020-12-18 09:52:18.741 ssh-REDACTED=
. 2020-12-18 09:52:18.742 Host key matches configured key fingerprint
. 2020-12-18 09:52:18.743 Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
. 2020-12-18 09:52:18.744 Initialised HMAC-SHA-256 outbound MAC algorithm
. 2020-12-18 09:52:18.744 Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
. 2020-12-18 09:52:18.745 Initialised HMAC-SHA-256 inbound MAC algorithm
. 2020-12-18 09:52:18.766 Reading key file "\\aiken\ProdCognos\ITExtracts\SSHKEY\myKey.ppk"
! 2020-12-18 09:52:18.771 Using username "REDACTED".
. 2020-12-18 09:52:19.609 Server offered these authentication methods: publickey
. 2020-12-18 09:52:19.610 Offered public key
. 2020-12-18 09:52:19.697 Offer of public key accepted
! 2020-12-18 09:52:19.698 Authenticating with public key "REDACTED"
. 2020-12-18 09:52:19.699 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "REDACTED": ")
. 2020-12-18 09:52:19.699 Using configured passphrase.
. 2020-12-18 09:52:19.884 Sent public key signature
. 2020-12-18 09:52:19.936 Access granted
. 2020-12-18 09:52:19.938 Opening main session channel
. 2020-12-18 09:52:20.206 Opened main channel
. 2020-12-18 09:52:20.309 Started a shell/command
. 2020-12-18 09:52:20.310 --------------------------------------------------------------------------
. 2020-12-18 09:52:20.310 Using SFTP protocol.
. 2020-12-18 09:52:20.311 Doing startup conversation with host.
> 2020-12-18 09:52:20.312 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2020-12-18 09:52:20.394 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2020-12-18 09:52:20.395 SFTP version 3 negotiated.
. 2020-12-18 09:52:20.395 Unknown server extension posix-rename@openssh.com="1"
. 2020-12-18 09:52:20.396 Supports statvfs@openssh.com extension version "2"
. 2020-12-18 09:52:20.397 Unknown server extension fstatvfs@openssh.com="2"
. 2020-12-18 09:52:20.397 Supports hardlink@openssh.com extension version "1"
. 2020-12-18 09:52:20.398 Unknown server extension fsync@openssh.com="1"
. 2020-12-18 09:52:20.398 We believe the server has signed timestamps bug
. 2020-12-18 09:52:20.399 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2020-12-18 09:52:20.399 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2020-12-18 09:52:20.400 Getting current directory name.
. 2020-12-18 09:52:20.400 Getting real path for '.'
> 2020-12-18 09:52:20.401 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2020-12-18 09:52:20.423 Type: SSH_FXP_NAME, Size: 23, Number: 16
. 2020-12-18 09:52:20.424 Real path is '/'
. 2020-12-18 09:52:20.425 Startup conversation with host finished.
< 2020-12-18 09:52:20.425 Script: Active session: [1] cofc@sftp.us.erezlife.com
> 2020-12-18 09:52:20.972 Script: pwd
< 2020-12-18 09:52:20.973 Script: /
> 2020-12-18 09:52:21.033 Script: put  -nopermissions -nopreservetime -transfer="automatic" -filemask="*>=14D" -resumesupport="100" -resume -- "\\aiken\IDPhotos\*.jpg" "/studentpics/"
. 2020-12-18 09:53:21.884 Copying 49519 files/directories to remote directory "/studentpics/" - total size: 2,608,605,894
. 2020-12-18 09:53:21.885   PrTime: No; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: 
. 2020-12-18 09:53:21.886   TM: M; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; EncryptNewFiles: Yes; ExcludeHiddenFiles: No; ExcludeEmptyDirectories: No; InclM: *>=14D; ResumeL: 0
. 2020-12-18 09:53:21.887   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2020-12-18 09:53:21.888 Getting real path for '/studentpics/'
> 2020-12-18 09:53:21.889 Type: SSH_FXP_REALPATH, Size: 22, Number: 272
< 2020-12-18 09:53:21.911 Type: SSH_FXP_NAME, Size: 45, Number: 272
. 2020-12-18 09:53:21.912 Real path is '/studentpics'
. 2020-12-18 09:53:21.914 File: '\\aiken\IDPhotos\20170247.jpg' [2020-12-18T08:41:48.262Z] [7946]
. 2020-12-18 09:53:21.917 Copying "\\aiken\IDPhotos\20170247.jpg" to remote directory started.
. 2020-12-18 09:53:21.917 Binary transfer mode selected.
. 2020-12-18 09:53:21.918 Opening remote file.
> 2020-12-18 09:53:21.918 Type: SSH_FXP_OPEN, Size: 50, Number: 515
< 2020-12-18 09:53:21.940 Type: SSH_FXP_STATUS, Size: 24, Number: 515
< 2020-12-18 09:53:21.940 Status code: 4, Message: 515, Server: Failure, Language:  
. 2020-12-18 09:53:21.941 Cannot create new file "/studentpics/20170247.jpg", checking if it exists already
> 2020-12-18 09:53:21.942 Type: SSH_FXP_LSTAT, Size: 34, Number: 775
< 2020-12-18 09:53:21.963 Type: SSH_FXP_ATTRS, Size: 37, Number: 775
> 2020-12-18 09:53:21.964 Type: SSH_FXP_OPEN, Size: 50, Number: 1027
< 2020-12-18 09:53:22.025 Type: SSH_FXP_STATUS, Size: 34, Number: 1027
< 2020-12-18 09:53:22.026 Status code: 3, Message: 1027, Server: Permission denied, Language:  
* 2020-12-18 09:53:22.027 (ETerminal) Permission denied.
* 2020-12-18 09:53:22.028 Error code: 3
* 2020-12-18 09:53:22.028 Error message from server: Permission denied
. 2020-12-18 09:53:22.029 Asking user:
. 2020-12-18 09:53:22.029 Cannot overwrite remote file '/studentpics/20170247.jpg'.$$
. 2020-12-18 09:53:22.029  
. 2020-12-18 09:53:22.030 Press 'Delete' to delete the file and create new one instead of overwriting it.$$ ("Permission denied.
. 2020-12-18 09:53:22.030 Error code: 3
. 2020-12-18 09:53:22.031 Error message from server: Permission denied")
< 2020-12-18 09:53:22.032 Script: Cannot overwrite remote file '/studentpics/20170247.jpg'.
< 2020-12-18 09:53:22.032 Script: Permission denied.
< 2020-12-18 09:53:22.033 Error code: 3
< 2020-12-18 09:53:22.033 Error message from server: Permission denied
* 2020-12-18 09:53:22.034 (ESkipFile) Cannot overwrite remote file '/studentpics/20170247.jpg'.$$
* 2020-12-18 09:53:22.035  
* 2020-12-18 09:53:22.035 Press 'Delete' to delete the file and create new one instead of overwriting it.$$
* 2020-12-18 09:53:22.036 Permission denied.
* 2020-12-18 09:53:22.036 Error code: 3
* 2020-12-18 09:53:22.037 Error message from server: Permission denied
. 2020-12-18 09:53:22.037 Copying finished: Transferred: 0, Elapsed: 0:00:00, CPS: 0/s
. 2020-12-18 09:53:22.051 Script: Failed
> 2020-12-18 09:53:22.831 Script: exit
. 2020-12-18 09:53:22.832 Script: Exit code: 1
. 2020-12-18 09:53:22.833 Closing connection.
. 2020-12-18 09:53:22.834 Sending special code: 1
. 2020-12-18 09:53:22.855 Session sent command exit status 0
. 2020-12-18 09:53:22.856 Main session channel closed
. 2020-12-18 09:53:22.857 All channels closed

Reply with quote E-mail

martin
Site Admin
martin avatar

Re: Keep getting Cannot overwrite remote file

Either the path is wrong – Shouldn't it be something like /home/username/studentpics/, rather than just /studentpics/?
Or you do not have permissions to write to that folder.
Are you able to upload the files anyhow? Using WinSCP GUI? Using any other way?

Reply with quote

Swindellvc@cofc.edu
Joined:
Posts:
12
Location:
Charleston, SC

Re: Keep getting Cannot overwrite remote file

The Error only happens with certain images...otherwise it works fine.
Is there some setting I need to set that I'm missing?

Yes I can upload with the GUI.

Basically I need to update images on the remote site that have changed or are new in the last X Days.

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar

Re: Keep getting Cannot overwrite remote file

Can you post a log that shows a successful upload of some image and a failed upload of another image, all other things being equal?

And/or log of a successful upload of an image in GUI and a log of failed upload of the same image in code?

Reply with quote

Swindellvc@cofc.edu

Right now

Right now I have it syncing the remote directory....i've only gotten one message where it could not overwrite...when it finishes i'll post the log
_________________
VC Swindell
Programmer/Analyst III
College of Charleston

Reply with quote E-mail

Advertisement

You can post new topics in this forum