我正在尝试将 WinSCP .NET 程序集 (V5.1.7.0) 用于 FTP 协议,但我在目标服务器上的文件路径方面遇到了困难。
问题是与服务器的任何连接(使用我自己的软件中的 WinSCP 可执行文件或 .NET 程序集)似乎会立即路由到用户的子目录(例如home/zild
),但文件需要上传到不同的目录(例如home/test
),用户对其有足够的权限(通过 WinSCP 可执行文件手动执行所需的操作来验证)。如果我尝试将远程路径设置为home/test/
or (绝对路径),它实际上在两种情况下都/home/test/
使用相对路径(例如)。home/zild/home/test
我认为 .NET 程序集只使用过绝对路径,所以这是一个惊喜。不幸的是,我找不到将路径设置为所需位置(home/test
)的方法。
有人可以解释一下我在这里做错了什么吗?我已经尝试搜索文档和 WinSCP 论坛,但仍然卡住。
编辑:附加信息
代码:
public bool Upload(string remoteDirectory, List<FileInfo> filesToUpload)
{
bool success = false;
try
{
using (Session session = new Session())
{
session.ExecutablePath = sessionExecutablePath;
session.Open(sessionOptions);
foreach (FileInfo fi in filesToUpload)
{
// fi.FullName: "XXX\\premiumparty_banner.gif"
// remoteDirectory: "/home/storage/test/"
TransferOperationResult transferResult = session.PutFiles(fi.FullName, remoteDirectory);
transferResult.Check();
if (transferResult.IsSuccess)
{
success = true;
}
else
{
// TO DO - write an error message (ideally for each failed item).
}
}
}
}
catch
{
}
return success;
}
我还没有使用日志记录,但是如果我能正常工作,我也会在这里发布日志。
我已经删除了本地计算机上的大部分文件路径,但是请注意它包含日文字符。
最后,请注意我也遇到了同样的问题session.ListDirectory()
。
EDIT2:日志文件
. 2013-11-18 17:26:33.064
--------------------------------------------------------------------------
. 2013-11-18 17:26:33.064 WinSCP Version 5.1.7 (Build 3446) (OS 6.1.7601 Service Pack 1)
. 2013-11-18 17:26:33.064 Configuration: nul
. 2013-11-18 17:26:33.065 Local account: jk_lee-PC\jamie_h
. 2013-11-18 17:26:33.065 Working directory: C:\Program Files (x86)\WinSCP
. 2013-11-18 17:26:33.065 Process ID: 1156
. 2013-11-18 17:26:33.065 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /xmllog="C:\Users\jamie_h\AppData\Local\Temp\wscp12BC.00EB2115.tmp" /xmlgroups /nointeractiveinput /dotnet=517 /ini=nul /log="C:\Users\jamie_h\Desktop\恋愛イベントツールのテストファイル\log1.log" /console /consoleinstance=_4796_348
. 2013-11-18 17:26:33.065 Time zone: Current: GMT+9, Standard: GMT+9, DST: GMT+10, DST Start: 1899/12/30, DST End: 1899/12/30
. 2013-11-18 17:26:33.065 Login time: 2013年11月18日 17:26:33
. 2013-11-18 17:26:33.065 --------------------------------------------------------------------------
. 2013-11-18 17:26:33.065 Session name: X@X.X.X.X (Ad-Hoc session)
. 2013-11-18 17:26:33.065 Host name: X.X.X.X (Port: 21)
. 2013-11-18 17:26:33.065 User name: X (Password: Yes, Key file: No)
. 2013-11-18 17:26:33.065 Tunnel: No
. 2013-11-18 17:26:33.065 Transfer Protocol: FTP
. 2013-11-18 17:26:33.065 Ping type: C, Ping interval: 30 sec; Timeout: 15 sec
. 2013-11-18 17:26:33.065 Proxy: none
. 2013-11-18 17:26:33.065 FTP: FTPS: None; Passive: Yes [Force IP: A]; List all: A
. 2013-11-18 17:26:33.065 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2013-11-18 17:26:33.065 Cache directory changes: Yes, Permanent: Yes
. 2013-11-18 17:26:33.065 DST mode: 1; Timezone offset: 0h 0m
. 2013-11-18 17:26:33.065 --------------------------------------------------------------------------
. 2013-11-18 17:26:33.068 Connecting to X.X.X.X ...
. 2013-11-18 17:26:33.086 Connected with X.X.X.X. Waiting for welcome message...
< 2013-11-18 17:26:33.095 220 ProFTPD 1.3.3e Server (ProFTPD Default Installation) [::ffff:X.X.X.X]
> 2013-11-18 17:26:33.095 USER X
< 2013-11-18 17:26:33.105 331 Password required for X
> 2013-11-18 17:26:33.105 PASS ***********************
< 2013-11-18 17:26:33.116 230 User X logged in
> 2013-11-18 17:26:33.116 SYST
< 2013-11-18 17:26:33.124 215 UNIX Type: L8
> 2013-11-18 17:26:33.124 FEAT
< 2013-11-18 17:26:33.133 211-Features:
< 2013-11-18 17:26:33.133 MDTM
< 2013-11-18 17:26:33.143 MFMT
< 2013-11-18 17:26:33.143 LANG it-IT;zh-CN;ja-JP;fr-FR;zh-TW;ru-RU;ko-KR;en-US;bg-BG
< 2013-11-18 17:26:33.143 TVFS
< 2013-11-18 17:26:33.143 MFF modify;UNIX.group;UNIX.mode;
< 2013-11-18 17:26:33.143 MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
< 2013-11-18 17:26:33.143 REST STREAM
< 2013-11-18 17:26:33.143 SIZE
< 2013-11-18 17:26:33.143 211 End
. 2013-11-18 17:26:33.143 Connected
. 2013-11-18 17:26:33.143 --------------------------------------------------------------------------
. 2013-11-18 17:26:33.143 Using FTP protocol.
. 2013-11-18 17:26:33.143 Doing startup conversation with host.
> 2013-11-18 17:26:33.143 PWD
< 2013-11-18 17:26:33.152 257 "/" is the current directory
. 2013-11-18 17:26:33.152 Getting current directory name.
. 2013-11-18 17:26:33.152 Startup conversation with host finished.
< 2013-11-18 17:26:33.153 Script: Active session: [1] X@X.X.X.X
> 2013-11-18 17:26:33.293 Script: put -nopermissions -preservetime -transfer="binary" -- "XXX\05_デザイン\スマフォ版\イベント\131101_クリスマス準備はパーティーで!?GACHA\premiumparty_banner.gif" "/home/storage/test/"
. 2013-11-18 17:26:33.294 Copying 1 files/directories to remote directory "/home/storage/test/"
. 2013-11-18 17:26:33.294 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2013-11-18 17:26:33.294 TM: B; ClAr: No; CPS: 0; InclM:
. 2013-11-18 17:26:33.294 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2013-11-18 17:26:33.296 File: "XXX\05_デザイン\スマフォ版\イベント\131101_クリスマス準備はパーティーで!?GACHA\premiumparty_banner.gif"
. 2013-11-18 17:26:33.305 Copying "XXX\05_デザイン\スマフォ版\イベント\131101_クリスマス準備はパーティーで!?GACHA\premiumparty_banner.gif" to remote directory started.
. 2013-11-18 17:26:33.306 Binary transfer mode selected.
. 2013-11-18 17:26:33.306 Starting upload of XXX\05_デザイン\スマフォ版\イベント\131101_クリスマス準備はパーティーで!?GACHA\premiumparty_banner.gif
> 2013-11-18 17:26:33.307 CWD /home/storage/test/
< 2013-11-18 17:26:33.315 250 CWD command successful
> 2013-11-18 17:26:33.315 PWD
< 2013-11-18 17:26:33.325 257 "/home/storage/test" is the current directory
> 2013-11-18 17:26:33.325 TYPE A
< 2013-11-18 17:26:33.333 200 Type set to A
> 2013-11-18 17:26:33.333 PASV
< 2013-11-18 17:26:33.342 227 Entering Passive Mode (X,X,X,X,234,80).
> 2013-11-18 17:26:33.342 MLSD
< 2013-11-18 17:26:33.358 150 Opening ASCII mode data connection for MLSD
. 2013-11-18 17:26:33.359 modify=20131114025545;perm=adfrw;size=115;type=file;unique=806U300826;UNIX.group=1000;UNIX.mode=0644;UNIX.owner=1000; カラーコード.txt
. 2013-11-18 17:26:33.359 modify=20131111065000;perm=adfrw;size=5904;type=file;unique=806U300825;UNIX.group=1000;UNIX.mode=0644;UNIX.owner=1000; premiumparty_button_gray.gif
. 2013-11-18 17:26:33.359 modify=20131118012640;perm=flcdmpe;type=pdir;unique=806U30208F;UNIX.group=1000;UNIX.mode=0755;UNIX.owner=1000; ..
. 2013-11-18 17:26:33.359 modify=20131111064838;perm=adfrw;size=9353;type=file;unique=806U300824;UNIX.group=1000;UNIX.mode=0644;UNIX.owner=1000; premiumparty_button.gif
. 2013-11-18 17:26:33.359 modify=20131113032811;perm=adfrw;size=14664;type=file;unique=806U3007A1;UNIX.group=1000;UNIX.mode=0644;UNIX.owner=1000; premiumparty_banner.gif
. 2013-11-18 17:26:33.359 modify=20131118012649;perm=flcdmpe;type=cdir;unique=806U302090;UNIX.group=1000;UNIX.mode=0755;UNIX.owner=1000; .
< 2013-11-18 17:26:33.368 226 Transfer complete
> 2013-11-18 17:26:33.371 TYPE I
< 2013-11-18 17:26:33.380 200 Type set to I
> 2013-11-18 17:26:33.380 PASV
< 2013-11-18 17:26:33.388 227 Entering Passive Mode (X,X,X,X,234,87).
> 2013-11-18 17:26:33.389 STOR premiumparty_banner.gif
< 2013-11-18 17:26:33.406 150 Opening BINARY mode data connection for premiumparty_banner.gif
< 2013-11-18 17:26:33.431 226 Transfer complete
> 2013-11-18 17:26:33.431 MFMT 20131113032811 premiumparty_banner.gif
< 2013-11-18 17:26:33.440 213 Modify=20131113032811; premiumparty_banner.gif
. 2013-11-18 17:26:33.440 Upload successful
> 2013-11-18 17:26:33.463 Script: exit
. 2013-11-18 17:26:33.463 Script: Exit code: 0
. 2013-11-18 17:26:33.464 Disconnected from server
这条线2013-11-18 17:26:33.152 257 "/" is the current directory
似乎不是真的......