WinSCP-重命名目录中的文件,禁止在其中列出/浏览

时间:2018-08-09 15:57:35

标签: ftp winscp

由于能够使用被动模式,因此我将使用WinSCP.com而不是FTP.exe。我已经开始将FTP脚本转换为WinSCP,并注意到正在发生的事情,但是我没有解决方案。

当前脚本-(ftpcommands.txt)

open ftp://user:pass@ftp.host.com/
cd /
put -transfer=binary "C:\Users\username\Desktop\test folder\myfile.7z.uploading"
mv "myfile.7z.uploading" "myfile.7z"
bye

从控制台窗口调用

Bin\WinSCP.com /script="ftpcommands.txt" /ini=nul

控制台窗口结果

Connecting to ftp.host.com ...
Connected
Starting the session...
Session started.
Active session: [1] user@ftp.host.com
/
myfile.7z.uploading       |         193 KB |  754.8 KB/s | binary | 100%
Can't get attributes of file 'myfile.7z.uploading'.
Could not retrieve file information
Permission denied.

WinSCP日志文件(使用/log=winscp.log开关时)

. 2018-08-09 13:09:43.432 --------------------------------------------------------------------------
. 2018-08-09 13:09:43.432 WinSCP Version 5.13.3 (Build 8565) (OS 10.0.17134 - Windows 10 Enterprise)
. 2018-08-09 13:09:43.432 Configuration: nul
. 2018-08-09 13:09:43.432 Log level: Normal
. 2018-08-09 13:09:43.432 Local account: GALAXY\username
. 2018-08-09 13:09:43.432 Working directory: C:\Users\username\Desktop\test folder
. 2018-08-09 13:09:43.432 Process ID: 30844
. 2018-08-09 13:09:43.432 Command-line: "C:\Users\username\Desktop\test folder\Bin\WinSCP.exe" /console=5.13.3 /consoleinstance=_18928_436 "/script=Logs\ftpcommands.txt" "/ini=nul" "/log=winscp.log" 
. 2018-08-09 13:09:43.432 Time zone: Current: GMT-4, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/11/2018, DST End: 11/4/2018
. 2018-08-09 13:09:43.510 Login time: Thursday, August 9, 2018 1:09:43 PM
. 2018-08-09 13:09:43.510 --------------------------------------------------------------------------
. 2018-08-09 13:09:43.510 Script: Retrospectively logging previous script records:
> 2018-08-09 13:09:43.510 Script: open ftp://user:***@ftp.host.com/
. 2018-08-09 13:09:43.510 --------------------------------------------------------------------------
. 2018-08-09 13:09:43.510 Session name: user@ftp.host.com (Ad-Hoc site)
. 2018-08-09 13:09:43.510 Host name: ftp.host.com (Port: 21)
. 2018-08-09 13:09:43.510 User name: user (Password: Yes, Key file: No, Passphrase: No)
. 2018-08-09 13:09:43.510 Transfer Protocol: FTP
. 2018-08-09 13:09:43.510 Ping type: Dummy, Ping interval: 30 sec; Timeout: 15 sec
. 2018-08-09 13:09:43.510 Disable Nagle: No
. 2018-08-09 13:09:43.510 Proxy: None
. 2018-08-09 13:09:43.510 Send buffer: 262144
. 2018-08-09 13:09:43.510 UTF: Auto
. 2018-08-09 13:09:43.510 FTPS: None [Client certificate: No]
. 2018-08-09 13:09:43.510 FTP: Passive: Yes [Force IP: Auto]; MLSD: Auto [List all: Auto]; HOST: Auto
. 2018-08-09 13:09:43.510 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2018-08-09 13:09:43.510 Cache directory changes: Yes, Permanent: Yes
. 2018-08-09 13:09:43.510 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2018-08-09 13:09:43.510 Timezone offset: 0h 0m
. 2018-08-09 13:09:43.510 --------------------------------------------------------------------------
. 2018-08-09 13:09:43.510 Connecting to ftp.host.com ...
. 2018-08-09 13:09:43.573 Connected with ftp.host.com. Waiting for welcome message...
< 2018-08-09 13:09:43.588 220-Welcome
< 2018-08-09 13:09:43.588 220-
< 2018-08-09 13:09:43.588 220-Company FTP Server
> 2018-08-09 13:09:43.588 USER user
< 2018-08-09 13:09:43.620 331 Password required for user
> 2018-08-09 13:09:43.620 PASS ****
< 2018-08-09 13:09:43.635 230 Logged on
> 2018-08-09 13:09:43.635 SYST
< 2018-08-09 13:09:43.651 215 UNIX emulated by FileZilla
> 2018-08-09 13:09:43.651 FEAT
< 2018-08-09 13:09:43.682 211-Features:
< 2018-08-09 13:09:43.682  MDTM
< 2018-08-09 13:09:43.698  REST STREAM
< 2018-08-09 13:09:43.698  SIZE
< 2018-08-09 13:09:43.698  MLST type*;size*;modify*;
< 2018-08-09 13:09:43.698  MLSD
< 2018-08-09 13:09:43.698  AUTH SSL
< 2018-08-09 13:09:43.698  AUTH TLS
< 2018-08-09 13:09:43.698  PROT
< 2018-08-09 13:09:43.698  PBSZ
< 2018-08-09 13:09:43.698  UTF8
< 2018-08-09 13:09:43.698  CLNT
< 2018-08-09 13:09:43.698  MFMT
< 2018-08-09 13:09:43.698  EPSV
< 2018-08-09 13:09:43.698  EPRT
< 2018-08-09 13:09:43.698 211 End
> 2018-08-09 13:09:43.698 CLNT WinSCP-release-5.13.3
< 2018-08-09 13:09:43.698 200 Don't care
> 2018-08-09 13:09:43.698 OPTS UTF8 ON
< 2018-08-09 13:09:43.713 202 UTF8 mode is always enabled. No need to send this command.
. 2018-08-09 13:09:43.713 Connected
. 2018-08-09 13:09:43.713 --------------------------------------------------------------------------
. 2018-08-09 13:09:43.713 Using FTP protocol.
. 2018-08-09 13:09:43.713 Doing startup conversation with host.
> 2018-08-09 13:09:43.713 PWD
< 2018-08-09 13:09:43.729 257 "/" is current directory.
. 2018-08-09 13:09:43.729 Getting current directory name.
. 2018-08-09 13:09:43.729 Startup conversation with host finished.
< 2018-08-09 13:09:43.729 Script: Active session: [1] user@ftp.host.com
> 2018-08-09 13:09:43.746 Script: cd /
. 2018-08-09 13:09:43.746 Changing directory to "/".
> 2018-08-09 13:09:43.746 CWD /
< 2018-08-09 13:09:43.767 250 CWD successful. "/" is current directory.
. 2018-08-09 13:09:43.767 Getting current directory name.
> 2018-08-09 13:09:43.767 PWD
< 2018-08-09 13:09:43.787 257 "/" is current directory.
< 2018-08-09 13:09:43.787 Script: /
> 2018-08-09 13:09:43.787 Script: put -transfer=binary "C:\Users\username\Desktop\test folder\myfile.7z.uploading"
. 2018-08-09 13:09:43.787 Copying 1 files/directories to remote directory "/" - total size: 198,017
. 2018-08-09 13:09:43.787   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: 
. 2018-08-09 13:09:43.787   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2018-08-09 13:09:43.787   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2018-08-09 13:09:43.787 File: 'C:\Users\username\Desktop\test folder\myfile.7z.uploading' [2018-08-09T15:41:57.040Z] [198017]
. 2018-08-09 13:09:43.787 Copying "C:\Users\username\Desktop\test folder\myfile.7z.uploading" to remote directory started.
. 2018-08-09 13:09:43.787 Binary transfer mode selected.
. 2018-08-09 13:09:43.787 Starting upload of C:\Users\username\Desktop\test folder\myfile.7z.uploading
> 2018-08-09 13:09:43.787 TYPE I
< 2018-08-09 13:09:43.803 200 Type set to I
> 2018-08-09 13:09:43.803 PASV
< 2018-08-09 13:09:43.818 227 Entering Passive Mode (1,2,3,4,17,147)
> 2018-08-09 13:09:43.818 STOR myfile.7z.uploading
. 2018-08-09 13:09:43.818 Connecting to 1.2.3.4:4499 ...
< 2018-08-09 13:09:43.865 150 Opening data channel for file upload to server of "/myfile.7z.uploading"
< 2018-08-09 13:09:44.084 226 Successfully transferred "/myfile.7z.uploading"
> 2018-08-09 13:09:44.084 MFMT 20180809154157 myfile.7z.uploading
< 2018-08-09 13:09:44.100 550 Permission denied
. 2018-08-09 13:09:44.100 Upload successful
. 2018-08-09 13:09:44.100 Transfer done: 'C:\Users\username\Desktop\test folder\myfile.7z.uploading' => '/myfile.7z.uploading' [198017]
. 2018-08-09 13:09:44.100 Copying finished: Transferred: 198,017, Elapsed: 0:00:00, CPS: 776,209/s
> 2018-08-09 13:09:44.100 Script: mv "myfile.7z.uploading" "myfile.7z"
. 2018-08-09 13:09:44.100 Listing file "myfile.7z.uploading".
. 2018-08-09 13:09:44.100 Retrieving file information...
> 2018-08-09 13:09:44.100 MLST /myfile.7z.uploading
< 2018-08-09 13:09:44.131 550 Permission denied.
. 2018-08-09 13:09:44.131 Could not retrieve file information
< 2018-08-09 13:09:44.131 Script: Can't get attributes of file 'myfile.7z.uploading'.
< 2018-08-09 13:09:44.131 Could not retrieve file information

< 2018-08-09 13:09:44.131 Permission denied.
. 2018-08-09 13:09:44.131 Script: Failed
. 2018-08-09 13:09:44.131 Script: Exit code: 1
. 2018-08-09 13:09:44.131 Disconnected from server

我可以连接到FTP服务器,登录,发送单个文件。这部分效果很好。然后,在发送文件后,我希望在控制台窗口中显示一条226 Successfully transferred消息。相反,我有一条消息显示以下内容...

  

无法获取文件'MyFileName.txt'的属性。

我的FTP服务器的设置方式是给定的唯一访问权限是...

  • 删除

没有授予用户任何类型的读取或列表权限。想法是让此脚本盲目地将文件转储到FTP服务器,检查FTP服务器是否返回成功的226消息,然后在文件上传后盲目地重命名文件。

一切都可以与FTP.exe一起使用,但是由于某些原因,我无法使其适用于WinSCP.com。所以这给我留下了两个问题...

  1. 使用WinSCP.com时是否可以显示实际的服务器响应?
  2. 是否可以关闭WinSCP.com在上传后尝试读取属性和文件信息之类的方式?

1 个答案:

答案 0 :(得分:2)

您不能阻止WinSCP在重命名之前检查文件。

但是正如您所暗示的那样,您可以使用WinSCP call command和FTP命令RNFRRNTO解决该问题:

call RNFR myfile.7z.uploading
call RNTO myfile.7z

对于MFMT,WinSCP使用它来更新上载文件的时间戳。如果失败,则WinSCP会静默忽略该错误。

但是,如果要避免在日志文件中出现错误,只需使用-nopreservetime switch of the put command