在WinSCP脚本中列出目录时出错

时间:2014-09-22 10:43:03

标签: scripting ftp winscp

我正在创建一个脚本来将大文件传输到远程目录。

$ cat scp.txt

option batch abort
option confirm off
open ftp:PROST:"xxxxxxxx"@216.101.13.11
pwd
ls
cd /cygdrive/d/Zilla/Rant/Logs
lcd D:/Logs
put FIX.4.2-DATA.event.current.log.20140921.gz

但它似乎找不到远程目录,即使它确实存在:

$ /myc/Program\ Files\ \(x86\)/WinSCP/WinSCP.com /script=scp.txt
batch           abort
confirm         off
Connecting to 216.101.13.11 ...
Connected with 216.101.13.11. Waiting for welcome message...
Connected
Starting the session...
Reading remote directory...
Session started.
Active session: [1] PROST@216.101.13.11
/
Error listing directory '/'.
Could not retrieve directory listing
Can't open data connection for transfer of "/"
(A)bort, (R)etry, (S)kip: Abort

日志文件:

. 2014-09-22 07:25:15.215 --------------------------------------------------------------------------
. 2014-09-22 07:25:15.215 WinSCP Version 5.5.4 (Build 4433) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2014-09-22 07:25:15.215 Configuration: HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\
. 2014-09-22 07:25:15.215 Local account: xxxxxxxxxxxxxxxxxx
. 2014-09-22 07:25:15.215 Working directory: D:\Logs
. 2014-09-22 07:25:15.215 Process ID: 9484
. 2014-09-22 07:25:15.215 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console=554 /consoleinstance=_3388_833 "/script=scp.txt" "/log=./scplog" 
. 2014-09-22 07:25:15.215 Time zone: Current: GMT-4, Standard: GMT-5 (Eastern Standard Time), DST: GMT-4 (Eastern Daylight Time), DST Start: 3/9/2014, DST End: 11/2/2014
. 2014-09-22 07:25:15.216 Login time: Monday, September 22, 2014 7:25:15 AM
. 2014-09-22 07:25:15.216 --------------------------------------------------------------------------
. 2014-09-22 07:25:15.216 Script: Retrospectively logging previous script records:
> 2014-09-22 07:25:15.216 Script: option batch abort
< 2014-09-22 07:25:15.216 Script: batch           abort     
> 2014-09-22 07:25:15.216 Script: option confirm off
< 2014-09-22 07:25:15.216 Script: confirm         off       
> 2014-09-22 07:25:15.216 Script: open ftp:PROST:***@xxx.xxx.xxx.xxx
. 2014-09-22 07:25:15.216 --------------------------------------------------------------------------
. 2014-09-22 07:25:15.216 Session name: PROST@xxx.xxx.xxx.xxx (Modified site)
. 2014-09-22 07:25:15.216 Host name: xxx.xxx.xxx.xxx (Port: 21)
. 2014-09-22 07:25:15.216 User name: PROST (Password: Yes, Key file: No)
. 2014-09-22 07:25:15.216 Tunnel: No
. 2014-09-22 07:25:15.216 Transfer Protocol: FTP
. 2014-09-22 07:25:15.216 Ping type: C, Ping interval: 30 sec; Timeout: 15 sec
. 2014-09-22 07:25:15.216 Proxy: none
. 2014-09-22 07:25:15.216 Send buffer: 262144
. 2014-09-22 07:25:15.216 UTF: 2
. 2014-09-22 07:25:15.216 FTP: FTPS: None; Passive: Yes [Force IP: A]; MLSD: A [List all: A]
. 2014-09-22 07:25:15.216 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2014-09-22 07:25:15.216 Cache directory changes: Yes, Permanent: Yes
. 2014-09-22 07:25:15.216 DST mode: 1; Timezone offset: 0h 0m
. 2014-09-22 07:25:15.216 --------------------------------------------------------------------------
. 2014-09-22 07:25:15.217 Connecting to xxx.xxx.xxx.xxx ...
. 2014-09-22 07:25:15.300 Connected with xxx.xxx.xxx.xxx. Waiting for welcome message...
< 2014-09-22 07:25:15.384 220-FileZilla Server version 0.9.45 beta
< 2014-09-22 07:25:15.384 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
< 2014-09-22 07:25:15.384 220 Please visit http://sourceforge.net/projects/filezilla/
> 2014-09-22 07:25:15.384 USER PROST
< 2014-09-22 07:25:15.467 331 Password required for prodny
> 2014-09-22 07:25:15.467 PASS **********
< 2014-09-22 07:25:15.551 230 Logged on
> 2014-09-22 07:25:15.551 SYST
< 2014-09-22 07:25:15.634 215 UNIX emulated by FileZilla
> 2014-09-22 07:25:15.634 FEAT
< 2014-09-22 07:25:15.717 211-Features:
< 2014-09-22 07:25:15.717  MDTM
< 2014-09-22 07:25:15.717  REST STREAM
< 2014-09-22 07:25:15.717  SIZE
< 2014-09-22 07:25:15.717  MLST type*;size*;modify*;
< 2014-09-22 07:25:15.717  MLSD
< 2014-09-22 07:25:15.718  UTF8
< 2014-09-22 07:25:15.718  CLNT
< 2014-09-22 07:25:15.718  MFMT
< 2014-09-22 07:25:15.718 211 End
. 2014-09-22 07:25:15.718 Connected
. 2014-09-22 07:25:15.718 --------------------------------------------------------------------------
. 2014-09-22 07:25:15.718 Using FTP protocol.
. 2014-09-22 07:25:15.718 Doing startup conversation with host.
> 2014-09-22 07:25:15.718 PWD
< 2014-09-22 07:25:15.801 257 "/" is current directory.
. 2014-09-22 07:25:15.801 Getting current directory name.
. 2014-09-22 07:25:15.801 Startup conversation with host finished.
< 2014-09-22 07:25:15.801 Script: Active session: [1] PROST@xxx.xxx.xxx.xxx
> 2014-09-22 07:25:15.801 Script: cd Rant/Logs
. 2014-09-22 07:25:15.801 Cached directory change via "Rant/Logs" to "/Rant/Logs".
. 2014-09-22 07:25:15.801 Getting current directory name.
< 2014-09-22 07:25:15.801 Script: /Rant/Logs
> 2014-09-22 07:25:15.801 Script: pwd
< 2014-09-22 07:25:15.801 Script: /Rant/Logs
> 2014-09-22 07:25:15.801 Script: lcd D:/Logs
< 2014-09-22 07:25:15.801 Script: D:\Logs
> 2014-09-22 07:25:15.801 Script: put FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
. 2014-09-22 07:25:15.802 Copying 1 files/directories to remote directory "/Rant/Logs"
. 2014-09-22 07:25:15.802   PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: 
. 2014-09-22 07:25:15.802   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: 
. 2014-09-22 07:25:15.802   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2014-09-22 07:25:15.802 File: 'FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz' [2014-09-21T21:00:10.230Z] [130873]
. 2014-09-22 07:25:15.802 Copying "FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz" to remote directory started.
. 2014-09-22 07:25:15.802 Binary transfer mode selected.
. 2014-09-22 07:25:15.802 Starting upload of FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
> 2014-09-22 07:25:15.802 CWD /Rant/Logs/
< 2014-09-22 07:25:15.885 250 CWD successful. "/Rant/Logs" is current directory.
> 2014-09-22 07:25:15.885 PWD
< 2014-09-22 07:25:15.978 257 "/Rant/Logs" is current directory.
> 2014-09-22 07:25:15.978 TYPE A
< 2014-09-22 07:25:16.071 200 Type set to A
> 2014-09-22 07:25:16.071 PASV
< 2014-09-22 07:25:16.154 227 Entering Passive Mode (xxx.xxx.xxx.xxx,228,142)
> 2014-09-22 07:25:16.154 MLSD
< 2014-09-22 07:25:26.151 425 Can't open data connection for transfer of "/Rant/Logs"
> 2014-09-22 07:25:26.151 SIZE FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
< 2014-09-22 07:25:26.233 550 File not found
> 2014-09-22 07:25:26.233 MDTM FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
< 2014-09-22 07:25:26.315 550 File not found
> 2014-09-22 07:25:26.315 TYPE I
< 2014-09-22 07:25:26.398 200 Type set to I
> 2014-09-22 07:25:26.398 PASV
< 2014-09-22 07:25:26.482 227 Entering Passive Mode (xxx.xxx.xxx.xxx,228,146)
> 2014-09-22 07:25:26.482 STOR FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
< 2014-09-22 07:25:37.303 425 Can't open data connection for transfer of "/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz"
. 2014-09-22 07:25:37.303 Copying files to remote side failed.
* 2014-09-22 07:25:37.303 (ExtException) **Copying files to remote side failed.**
* 2014-09-22 07:25:37.303 Can't open data connection for transfer of "/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz"
. 2014-09-22 07:25:37.303 Asking user:
. 2014-09-22 07:25:37.303 Error transferring file 'FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz'. ("Copying files to remote side failed.","Can't open data connection for transfer of ""/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz""")
< 2014-09-22 07:25:37.303 Script: Error transferring file 'FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz'.
< 2014-09-22 07:25:37.303 Script: Copying files to remote side failed.

< 2014-09-22 07:25:37.303 Can't open data connection for transfer of "/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz"
* 2014-09-22 07:25:37.304 (EScpSkipFile) Error transferring file 'FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz'.
* 2014-09-22 07:25:37.304 Copying files to remote side failed.
* 2014-09-22 07:25:37.304 Can't open data connection for transfer of "/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz"
. 2014-09-22 07:25:37.304 Script: Failed
. 2014-09-22 07:25:37.304 Script: Exit code: 1
. 2014-09-22 07:25:37.304 Disconnected from server

1 个答案:

答案 0 :(得分:2)

> 2014-09-22 07:25:26.398 PASV
< 2014-09-22 07:25:26.482 227 Entering Passive Mode (xxx.xxx.xxx.xxx,228,146)
> 2014-09-22 07:25:26.482 STOR FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz
< 2014-09-22 07:25:37.303 425 Can't open data connection for transfer of "/Rant/Logs/FIX.4.2-DATA_FIX_xxxxx-FIX-BRIDGE.event.current.log.20140921.gz"

服务器可能位于防火墙后面,未正确配置防火墙以允许FTP数据连接。

您需要确保防火墙允许服务器用于被动模式传输的端口上的入站连接。

有关详细信息,请参阅我的network configuration for FTP passive mode指南。


或者,您可以尝试将活动模式与WinSCP一起使用。

open ... -passive=off

请参阅https://winscp.net/eng/docs/scriptcommand_open

通常情况下,主动模式无法正常工作,您需要为数据通道打开本地防火墙。