代码之家  ›  专栏  ›  技术社区  ›  Arvo Bowen

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

  •  2
  • Arvo Bowen  · 技术社区  · 6 年前

    我要开始使用 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 回复  |  直到 6 年前
        1
  •  2
  •   Martin Prikryl    6 年前

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

    但正如你所暗示的,你可以用 WinSCP call command 和FTP命令 RNFR RNTO :

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

    至于 MFMT ,WinSCP使用它更新上载文件的时间戳。如果失败,WinSCP会自动忽略错误。

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