使用WinSCP进行sFTP和FTP文件传输 - 使用以下代码:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = WinSCP.Protocol.Sftp,
PortNumber = int.Parse(sFTP_port_number),
SshHostKeyFingerprint = sFTP_SshHostKeyFingerprint,
HostName = sFTP_host_Name,
UserName = sFTP_UserName,
Password = sFTP_Password
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
transferOptions.TransferMode = TransferMode.Binary;
transferResult = session.PutFiles(sFTP_localPath, sFTP_remotepath, false, transferOptions);
UpdateStatus(ConfigDictionary, transferResult.IsSuccess);
// Throw on any error
transferResult.Check();
// log results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Logger.LogInfo("Upload of {0} succeeded ", transfer.FileName);
}
}
使用sFTP协议时,一切都按预期工作;使用WinSCP.Protocol.ftp
时 - 程序控制移至transferResult = session.PutFiles(sFTP_localPath, sFTP_remotepath, false, transferOptions);
控件永远不会再次返回程序。甚至尝试超时;它根本不起作用。是什么工作?
编辑:文件被复制到ftp位置。日志文件不断增长。
记录:
. 2015-04-15 16:02:15.453 --------------------------------------------------------------------------
. 2015-04-15 16:02:15.453 WinSCP Version 5.7.1 (Build 5235) (OS 6.1.7601 Service Pack 1 - Windows 7 Professional)
. 2015-04-15 16:02:15.453 Configuration: nul
. 2015-04-15 16:02:15.453 Log level: Normal
. 2015-04-15 16:02:15.453 Local account: KOTTARA\murali.uppangala
. 2015-04-15 16:02:15.453 Working directory: C:\Program Files\WinSCP
. 2015-04-15 16:02:15.453 Process ID: 4416
. 2015-04-15 16:02:15.453 Command-line: "C:\Program Files\WinSCP\winscp.exe" /xmllog="C:\Users\murali.uppangala\AppData\Local\Temp\wscp1D0C.01079695.tmp" /xmlgroups /nointeractiveinput /dotnet=571 /ini=nul /log="C:\Users\murali.uppangala\Desktop\TODAY\murali@127.0.0.1.log" /console /consoleinstance=_7436_39155797_72
. 2015-04-15 16:02:15.453 Time zone: Current: GMT+5:30 (India Standard Time), No DST
. 2015-04-15 16:02:15.453 Login time: Wednesday, April 15, 2015 4:02:15 PM
. 2015-04-15 16:02:15.453 --------------------------------------------------------------------------
. 2015-04-15 16:02:15.453 Script: Retrospectively logging previous script records:
> 2015-04-15 16:02:15.453 Script: option batch on
< 2015-04-15 16:02:15.453 Script: batch on
< 2015-04-15 16:02:15.453 Script: reconnecttime 120
> 2015-04-15 16:02:15.453 Script: option confirm off
< 2015-04-15 16:02:15.453 Script: confirm off
> 2015-04-15 16:02:15.453 Script: option reconnecttime 120
< 2015-04-15 16:02:15.453 Script: reconnecttime 120
> 2015-04-15 16:02:15.453 Script: open ftp://murali:***@127.0.0.1:21 -passive=1 -timeout=15
. 2015-04-15 16:02:15.453 --------------------------------------------------------------------------
. 2015-04-15 16:02:15.453 Session name: murali@127.0.0.1 (Ad-Hoc site)
. 2015-04-15 16:02:15.453 Host name: 127.0.0.1 (Port: 21)
. 2015-04-15 16:02:15.453 User name: murali (Password: Yes, Key file: No)
. 2015-04-15 16:02:15.453 Transfer Protocol: FTP
. 2015-04-15 16:02:15.453 Ping type: C, Ping interval: 30 sec; Timeout: 15 sec
. 2015-04-15 16:02:15.453 Disable Nagle: No
. 2015-04-15 16:02:15.453 Proxy: none
. 2015-04-15 16:02:15.453 Send buffer: 262144
. 2015-04-15 16:02:15.453 UTF: 2
. 2015-04-15 16:02:15.453 FTP: FTPS: None; Passive: Yes [Force IP: A]; MLSD: A [List all: A]
. 2015-04-15 16:02:15.453 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2015-04-15 16:02:15.453 Cache directory changes: Yes, Permanent: Yes
. 2015-04-15 16:02:15.453 Timezone offset: 0h 0m
. 2015-04-15 16:02:15.453 --------------------------------------------------------------------------
. 2015-04-15 16:02:15.453 Connecting to 127.0.0.1 ...
. 2015-04-15 16:02:15.469 Connected with 127.0.0.1. Waiting for welcome message...
< 2015-04-15 16:02:15.469 220 Hello, I'm freeFTPd 1.0
> 2015-04-15 16:02:15.469 USER murali
< 2015-04-15 16:02:15.469 331 Password required for murali
> 2015-04-15 16:02:15.469 PASS *********
< 2015-04-15 16:02:15.469 230 User murali logged in
> 2015-04-15 16:02:15.469 SYST
< 2015-04-15 16:02:15.469 215 UNIX Type: L8
> 2015-04-15 16:02:15.469 FEAT
< 2015-04-15 16:02:15.485 211-Extensions supported
< 2015-04-15 16:02:15.485 SIZE
< 2015-04-15 16:02:15.485 MDTM
< 2015-04-15 16:02:15.485 REST
< 2015-04-15 16:02:15.485 UTF8
< 2015-04-15 16:02:15.485 OPTS MODE;UTF8;MLST
< 2015-04-15 16:02:15.485 MODE Z
< 2015-04-15 16:02:15.485 XCRC
< 2015-04-15 16:02:15.485 XMD5
< 2015-04-15 16:02:15.485 XSHA1
< 2015-04-15 16:02:15.485 CLNT
< 2015-04-15 16:02:15.485 MLST Type*;Size*;Create;Modify*;Perm
< 2015-04-15 16:02:15.485 211 End of FEAT
> 2015-04-15 16:02:15.485 CLNT FileZilla
< 2015-04-15 16:02:15.485 200 Ok, welcome
> 2015-04-15 16:02:15.485 OPTS UTF8 ON
< 2015-04-15 16:02:15.485 200 OPTS UTF8 is set to ON.
. 2015-04-15 16:02:15.485 Connected
. 2015-04-15 16:02:15.485 --------------------------------------------------------------------------
. 2015-04-15 16:02:15.485 Using FTP protocol.
. 2015-04-15 16:02:15.485 Doing startup conversation with host.
> 2015-04-15 16:02:15.485 PWD
< 2015-04-15 16:02:15.500 257 "/" is current directory
. 2015-04-15 16:02:15.500 Getting current directory name.
. 2015-04-15 16:02:15.500 Startup conversation with host finished.
< 2015-04-15 16:02:15.500 Script: Active session: [1] murali@127.0.0.1
> 2015-04-15 16:02:15.641 Script: pwd
< 2015-04-15 16:02:15.641 Script: /
> 2015-04-15 16:02:15.797 Script: put -nopermissions -preservetime -transfer="binary" -- "C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach" "/"
. 2015-04-15 16:02:15.797 Copying 1 files/directories to remote directory "/"
. 2015-04-15 16:02:15.797 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2015-04-15 16:02:15.797 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2015-04-15 16:02:15.797 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2015-04-15 16:02:15.797 File: 'C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach' [2015-03-31T12:03:52.164Z] [33308]
. 2015-04-15 16:02:15.797 Copying "C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach" to remote directory started.
. 2015-04-15 16:02:15.797 Binary transfer mode selected.
. 2015-04-15 16:02:15.797 Starting upload of C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach
> 2015-04-15 16:02:15.797 TYPE A
< 2015-04-15 16:02:15.812 200 TYPE set to ASCII
> 2015-04-15 16:02:15.812 PASV
< 2015-04-15 16:02:15.812 227 Entering passive mode (127,0,0,1,235,82)
> 2015-04-15 16:02:15.812 MLSD
< 2015-04-15 16:02:15.812 150 Opening ASCII mode data connection
. 2015-04-15 16:02:15.812 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; .
. 2015-04-15 16:02:15.812 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; ..
. 2015-04-15 16:02:15.812 type=file;size=33308;create=20150415102438;modify=20150415103147;perm=fdraw; batchpayment.ach
. 2015-04-15 16:02:15.812 type=dir;size=0;create=20150401144129;modify=20150401144129;perm=fdlempc; Keys
< 2015-04-15 16:02:15.812 226 Directory send OK
> 2015-04-15 16:02:15.812 TYPE I
< 2015-04-15 16:02:15.812 200 TYPE set to BINARY
> 2015-04-15 16:02:15.812 PASV
< 2015-04-15 16:02:15.812 227 Entering passive mode (127,0,0,1,235,84)
> 2015-04-15 16:02:15.812 STOR batchpayment.ach
< 2015-04-15 16:02:15.828 150 Opening BINARY mode data connection for batchpayment.ach
. 2015-04-15 16:02:30.664 Timeout detected. (control connection)
. 2015-04-15 16:02:30.664 Copying files to remote side failed.
. 2015-04-15 16:02:30.664 Connection was lost, asking what to do.
. 2015-04-15 16:02:30.664 Asking user:
. 2015-04-15 16:02:30.664 Lost connection. ("Timeout detected. (control connection)","Copying files to remote side failed.")
< 2015-04-15 16:02:30.664 Script: Lost connection.
< 2015-04-15 16:02:30.664 Script: Timeout detected. (control connection)
< 2015-04-15 16:02:30.664 Copying files to remote side failed.
< 2015-04-15 16:02:35.748 Script: Connecting to 127.0.0.1 ...
. 2015-04-15 16:02:35.748 Connecting to 127.0.0.1 ...
. 2015-04-15 16:02:35.748 Connected with 127.0.0.1. Waiting for welcome message...
< 2015-04-15 16:02:35.748 220 Hello, I'm freeFTPd 1.0
> 2015-04-15 16:02:35.748 USER murali
< 2015-04-15 16:02:35.748 331 Password required for murali
> 2015-04-15 16:02:35.748 PASS *********
< 2015-04-15 16:02:35.748 230 User murali logged in
> 2015-04-15 16:02:35.748 SYST
< 2015-04-15 16:02:35.748 215 UNIX Type: L8
> 2015-04-15 16:02:35.748 FEAT
< 2015-04-15 16:02:35.748 211-Extensions supported
< 2015-04-15 16:02:35.748 SIZE
< 2015-04-15 16:02:35.748 MDTM
< 2015-04-15 16:02:35.748 REST
< 2015-04-15 16:02:35.748 UTF8
< 2015-04-15 16:02:35.748 OPTS MODE;UTF8;MLST
< 2015-04-15 16:02:35.748 MODE Z
< 2015-04-15 16:02:35.748 XCRC
< 2015-04-15 16:02:35.748 XMD5
< 2015-04-15 16:02:35.748 XSHA1
< 2015-04-15 16:02:35.748 CLNT
< 2015-04-15 16:02:35.748 MLST Type*;Size*;Create;Modify*;Perm
< 2015-04-15 16:02:35.748 211 End of FEAT
> 2015-04-15 16:02:35.748 CLNT FileZilla
< 2015-04-15 16:02:35.748 200 Ok, welcome
> 2015-04-15 16:02:35.748 OPTS UTF8 ON
< 2015-04-15 16:02:35.748 200 OPTS UTF8 is set to ON.
< 2015-04-15 16:02:35.748 Script: Connected
. 2015-04-15 16:02:35.748 Connected
. 2015-04-15 16:02:35.748 Doing startup conversation with host.
< 2015-04-15 16:02:35.748 Script: Starting the session...
> 2015-04-15 16:02:35.748 PWD
< 2015-04-15 16:02:35.748 257 "/" is current directory
. 2015-04-15 16:02:35.748 Changing directory to "/".
> 2015-04-15 16:02:35.748 CWD /
< 2015-04-15 16:02:35.748 250 CWD command successful
. 2015-04-15 16:02:35.748 Getting current directory name.
> 2015-04-15 16:02:35.748 PWD
< 2015-04-15 16:02:35.748 257 "/" is current directory
. 2015-04-15 16:02:35.748 Startup conversation with host finished.
< 2015-04-15 16:02:35.748 Script: Session started.
. 2015-04-15 16:02:35.748 File: 'C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach' [2015-03-31T12:03:52.164Z] [33308]
. 2015-04-15 16:02:35.748 Copying "C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach" to remote directory started.
. 2015-04-15 16:02:35.748 Binary transfer mode selected.
. 2015-04-15 16:02:35.748 Starting upload of C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach
> 2015-04-15 16:02:35.748 TYPE A
< 2015-04-15 16:02:35.748 200 TYPE set to ASCII
> 2015-04-15 16:02:35.748 PASV
< 2015-04-15 16:02:35.748 227 Entering passive mode (127,0,0,1,235,94)
> 2015-04-15 16:02:35.748 MLSD
< 2015-04-15 16:02:35.763 150 Opening ASCII mode data connection
. 2015-04-15 16:02:35.763 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; .
. 2015-04-15 16:02:35.763 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; ..
. 2015-04-15 16:02:35.763 type=file;size=33308;create=20150415102438;modify=20150415103215;perm=fdraw; batchpayment.ach
. 2015-04-15 16:02:35.763 type=dir;size=0;create=20150401144129;modify=20150401144129;perm=fdlempc; Keys
< 2015-04-15 16:02:35.763 226 Directory send OK
> 2015-04-15 16:02:35.763 TYPE I
< 2015-04-15 16:02:35.763 200 TYPE set to BINARY
> 2015-04-15 16:02:35.763 PASV
< 2015-04-15 16:02:35.763 227 Entering passive mode (127,0,0,1,235,96)
> 2015-04-15 16:02:35.763 STOR batchpayment.ach
< 2015-04-15 16:02:35.763 150 Opening BINARY mode data connection for batchpayment.ach
. 2015-04-15 16:02:50.943 Timeout detected. (control connection)
. 2015-04-15 16:02:50.943 Copying files to remote side failed.
. 2015-04-15 16:02:50.943 Connection was lost, asking what to do.
. 2015-04-15 16:02:50.943 Asking user:
. 2015-04-15 16:02:50.943 Lost connection. ("Timeout detected. (control connection)","Copying files to remote side failed.")
< 2015-04-15 16:02:50.943 Script: Lost connection.
< 2015-04-15 16:02:50.943 Script: Timeout detected. (control connection)
< 2015-04-15 16:02:50.943 Copying files to remote side failed.
< 2015-04-15 16:02:56.013 Script: Connecting to 127.0.0.1 ...
. 2015-04-15 16:02:56.013 Connecting to 127.0.0.1 ...
. 2015-04-15 16:02:56.013 Connected with 127.0.0.1. Waiting for welcome message...
< 2015-04-15 16:02:56.013 220 Hello, I'm freeFTPd 1.0
> 2015-04-15 16:02:56.013 USER murali
< 2015-04-15 16:02:56.013 331 Password required for murali
> 2015-04-15 16:02:56.013 PASS *********
< 2015-04-15 16:02:56.013 230 User murali logged in
> 2015-04-15 16:02:56.013 SYST
< 2015-04-15 16:02:56.013 215 UNIX Type: L8
> 2015-04-15 16:02:56.013 FEAT
< 2015-04-15 16:02:56.013 211-Extensions supported
< 2015-04-15 16:02:56.013 SIZE
< 2015-04-15 16:02:56.013 MDTM
< 2015-04-15 16:02:56.013 REST
< 2015-04-15 16:02:56.013 UTF8
< 2015-04-15 16:02:56.013 OPTS MODE;UTF8;MLST
< 2015-04-15 16:02:56.013 MODE Z
< 2015-04-15 16:02:56.013 XCRC
< 2015-04-15 16:02:56.013 XMD5
< 2015-04-15 16:02:56.013 XSHA1
< 2015-04-15 16:02:56.013 CLNT
< 2015-04-15 16:02:56.013 MLST Type*;Size*;Create;Modify*;Perm
< 2015-04-15 16:02:56.013 211 End of FEAT
> 2015-04-15 16:02:56.013 CLNT FileZilla
< 2015-04-15 16:02:56.013 200 Ok, welcome
> 2015-04-15 16:02:56.013 OPTS UTF8 ON
< 2015-04-15 16:02:56.013 200 OPTS UTF8 is set to ON.
< 2015-04-15 16:02:56.013 Script: Connected
. 2015-04-15 16:02:56.013 Connected
. 2015-04-15 16:02:56.013 Doing startup conversation with host.
< 2015-04-15 16:02:56.013 Script: Starting the session...
> 2015-04-15 16:02:56.013 PWD
< 2015-04-15 16:02:56.013 257 "/" is current directory
. 2015-04-15 16:02:56.013 Changing directory to "/".
> 2015-04-15 16:02:56.013 CWD /
< 2015-04-15 16:02:56.013 250 CWD command successful
. 2015-04-15 16:02:56.013 Getting current directory name.
> 2015-04-15 16:02:56.013 PWD
< 2015-04-15 16:02:56.013 257 "/" is current directory
. 2015-04-15 16:02:56.013 Startup conversation with host finished.
< 2015-04-15 16:02:56.013 Script: Session started.
. 2015-04-15 16:02:56.013 File: 'C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach' [2015-03-31T12:03:52.164Z] [33308]
. 2015-04-15 16:02:56.013 Copying "C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach" to remote directory started.
. 2015-04-15 16:02:56.013 Binary transfer mode selected.
. 2015-04-15 16:02:56.013 Starting upload of C:\Users\murali.uppangala\Desktop\TODAY\BatchPayment\batchpayment.ach
> 2015-04-15 16:02:56.013 TYPE A
< 2015-04-15 16:02:56.013 200 TYPE set to ASCII
> 2015-04-15 16:02:56.013 PASV
< 2015-04-15 16:02:56.013 227 Entering passive mode (127,0,0,1,235,106)
> 2015-04-15 16:02:56.028 MLSD
< 2015-04-15 16:02:56.028 150 Opening ASCII mode data connection
. 2015-04-15 16:02:56.028 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; .
. 2015-04-15 16:02:56.028 type=dir;size=0;create=20150401141111;modify=20150415102438;perm=fdlempc; ..
. 2015-04-15 16:02:56.028 type=file;size=33308;create=20150415102438;modify=20150415103235;perm=fdraw; batchpayment.ach
. 2015-04-15 16:02:56.028 type=dir;size=0;create=20150401144129;modify=20150401144129;perm=fdlempc; Keys
< 2015-04-15 16:02:56.028 226 Directory send OK
> 2015-04-15 16:02:56.028 TYPE I
< 2015-04-15 16:02:56.028 200 TYPE set to BINARY
> 2015-04-15 16:02:56.028 PASV
< 2015-04-15 16:02:56.028 227 Entering passive mode (127,0,0,1,235,108)
> 2015-04-15 16:02:56.028 STOR batchpayment.ach
< 2015-04-15 16:02:56.028 150 Opening BINARY mode data connection for batchpayment.ach