WinSCP 5.13 .NET assembly // Session.MoveFile without the rights to list

Advertisement

abillon
Joined:
Posts:
11
Location:
France

WinSCP 5.13 .NET assembly // Session.MoveFile without the rights to list

Hello,

I have installed WinSCP 5.13 .NET assembly to correct a "Invalid access to memory" exception a few weeks ago. So far, it looks good, I don't have these exceptions anymore.

However, in the version 5.13, I have seen in the release note that the MoveFile method behaviour have changed. The Session.MoveFile fails with a SessionRemoteException when the remote file can not be listed.

I have a partner that wants me to send files on his FTP server where :
1. I don't have the rights to list directories
2. The partner ask me to send the files with a temporary extension and then rename it

Do I have a way to make it work with the 5.13 version ?
If not, could you add an optional argument to Session.MoveFile to be able to get the same behaviour than in the version 5.11 ?

For the moment, I have the 2 versions of the assembly following the rights I have on the remote sites.

Thank you in advance for your help !

Alex

Reply with quote

Advertisement

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

Re: WinSCP 5.13 .NET assembly // Session.MoveFile without the rights to list

abillon wrote:

Do I have a way to make it work with the 5.13 version ?
That's too broad question. It heavily depends on how the permissions are configured and what commands are restricted. WinSCP does not need permissions to list directories. I needs permissions to retrieve file attributes.

Reply with quote

abillon
Joined:
Posts:
11
Location:
France

Hello Martin,

Thanks for your reply. What I see from my side.

My Code (powershell)
# $remoteNameSuffixed = "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH"
# $remoteName = "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF"
# Sending of the file with a suffix
$transferResult = $session.PutFiles($localFullName, $remoteNameSuffixed, $false, $transferOptions)

# Create an exception if the upload failed
$transferResult.Check()

# Remove the suffix
$session.MoveFile($remoteNameSuffixed, $remoteName)

Here are the logs for the sending of the same file on a FTP server where I have the rights the write but not to list.

With the version 5.11.1, the MoveFile sends the RNFR & RNTO commands and the server send back the success code 250 RNTO command successful
> 2018-03-05 09:19:42.325 Script: put -nopermissions -preservetime -transfer="binary" -- "D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg" "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH"
. 2018-03-05 09:19:42.325 Copying 1 files/directories to remote directory "/pfm/xyric_ged/" - total size: 468 887
. 2018-03-05 09:19:42.325 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
. 2018-03-05 09:19:42.325 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2018-03-05 09:19:42.325 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2018-03-05 09:19:42.325 File: 'D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg' [2018-03-02T21:06:06.994Z] [468887]
. 2018-03-05 09:19:42.325 Copying "D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg" to remote directory started.
. 2018-03-05 09:19:42.325 Binary transfer mode selected.
. 2018-03-05 09:19:42.325 Starting upload of D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg
> 2018-03-05 09:19:42.340 CWD /pfm/xyric_ged
< 2018-03-05 09:19:42.418 250 CWD command successful.
> 2018-03-05 09:19:42.418 PWD
< 2018-03-05 09:19:42.496 257 "/pfm/xyric_ged" is current directory.
> 2018-03-05 09:19:42.496 TYPE I
< 2018-03-05 09:19:42.637 200 Type set to I.
> 2018-03-05 09:19:42.637 PASV
< 2018-03-05 09:19:42.746 227 Entering Passive Mode (xxx,xxx,xxx,xxx,220,222).
> 2018-03-05 09:19:42.746 STOR PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
. 2018-03-05 09:19:42.746 Connecting to xxx.xxx.xxx.xxx:56542 ...
< 2018-03-05 09:19:42.871 150 Opening BINARY mode data connection.
< 2018-03-05 09:19:43.699 226 Transfer complete.
> 2018-03-05 09:19:43.699 MDTM 20180302210606 PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
< 2018-03-05 09:19:43.809 213 20180302210606
. 2018-03-05 09:19:43.809 Upload successful
. 2018-03-05 09:19:44.043 Transfer done: 'D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg' => '/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH' [468887]
. 2018-03-05 09:19:44.043 Copying finished: Transferred: 468 887, Elapsed: 0:00:01, CPS: 386 094/s
> 2018-03-05 09:19:44.890 Script: mv "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH" "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF"
. 2018-03-05 09:19:44.906 Moving file "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH" to "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF".
> 2018-03-05 09:19:44.906 RNFR /pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
< 2018-03-05 09:19:44.984 350 Requested file action pending further information.
> 2018-03-05 09:19:44.984 RNTO /pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF
< 2018-03-05 09:19:45.062 250 RNTO command successful.

< 2018-03-05 09:19:45.062 Script: /pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH

With the version 5.13, the MoveFile sends a SIZE command to the server and then I get an exception.
Exception lors de l'appel de « MoveFile » avec « 2 » argument(s) : « Can't get attributes of file '/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH'.
Could not retrieve file information »

> 2018-03-02 22:06:09.472 Script: put -nopermissions -preservetime -transfer="binary" -- "D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg" "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH"
. 2018-03-02 22:06:09.472 Copying 1 files/directories to remote directory "/pfm/xyric_ged/" - total size: 468 887
. 2018-03-02 22:06:09.472 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
. 2018-03-02 22:06:09.472 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2018-03-02 22:06:09.472 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2018-03-02 22:06:09.472 File: 'D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg' [2018-03-02T21:06:06.994Z] [468887]
. 2018-03-02 22:06:09.472 Copying "D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg" to remote directory started.
. 2018-03-02 22:06:09.472 Binary transfer mode selected.
. 2018-03-02 22:06:09.472 Starting upload of D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg
> 2018-03-02 22:06:09.472 CWD /pfm/xyric_ged
< 2018-03-02 22:06:09.552 250 CWD command successful.
> 2018-03-02 22:06:09.552 PWD
< 2018-03-02 22:06:09.630 257 "/pfm/xyric_ged" is current directory.
> 2018-03-02 22:06:09.630 TYPE I
< 2018-03-02 22:06:09.708 200 Type set to I.
> 2018-03-02 22:06:09.708 PASV
< 2018-03-02 22:06:09.788 227 Entering Passive Mode (xxx,xxx,xxx,xxx,251,200).
> 2018-03-02 22:06:09.788 STOR PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
. 2018-03-02 22:06:09.788 Connecting to xxx.xxx.xxx.xxx:64456 ...
< 2018-03-02 22:06:09.851 150 Opening BINARY mode data connection.
< 2018-03-02 22:06:10.758 226 Transfer complete.
> 2018-03-02 22:06:10.758 MDTM 20180302210606 PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
< 2018-03-02 22:06:10.836 213 20180302210606
. 2018-03-02 22:06:10.836 Upload successful
. 2018-03-02 22:06:10.836 Transfer done: 'D:\EDI\out\SpfmGEDJPG\PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg' => '/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH' [468887]
. 2018-03-02 22:06:10.836 Copying finished: Transferred: 468 887, Elapsed: 0:00:01, CPS: 459 393/s
> 2018-03-02 22:06:11.134 Script: mv "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH" "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF"
. 2018-03-02 22:06:11.134 Listing file "/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH".
. 2018-03-02 22:06:11.134 Retrieving file information...
> 2018-03-02 22:06:11.134 PWD
< 2018-03-02 22:06:11.212 257 "/pfm/xyric_ged" is current directory.
> 2018-03-02 22:06:11.212 CWD /pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
< 2018-03-02 22:06:12.181 550
> 2018-03-02 22:06:12.181 TYPE I
< 2018-03-02 22:06:12.181 200 Type set to I.
> 2018-03-02 22:06:12.181 SIZE /pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH
< 2018-03-02 22:06:12.181 550

. 2018-03-02 22:06:12.181 Could not retrieve file information
< 2018-03-02 22:06:12.181 Script: Can't get attributes of file '/pfm/xyric_ged/PFM1656_CD1802-665637_NN-180208566_POD_180302152215696_30538_001.jpeg.TRF.TempH'.
< 2018-03-02 22:06:12.181 Could not retrieve file information
. 2018-03-02 22:06:12.181 Script: Failed

I guess I could use Session.ExecuteCommand as a workaround to send RNFR and RNTO to the server but the change on the Session.MoveFile feels like a regression to me.
It would be nice to be able to pass an argument to tell to the MoveFile method to check or not the existence of the file before moving it so you could keep the behaviour of the versions 5.11.1 & 5.13

Reply with quote

martin
Site Admin
martin avatar

Re: WinSCP 5.13 .NET assembly // Session.MoveFile without the rights to list

OK, I understand that this caused you troubles. Though this all seems like a very obscure requirement.

Cannot you just upload the file to some temporary location (like /tmp), where you have permissions to read, and rename/move the file from there to the final location and name?

Reply with quote

Advertisement

You can post new topics in this forum