我正在尝试将WinSCP .NET程序集(V5.1.7.0)用于FTP协议,但我在目标服务器上遇到文件路径问题。
问题是与服务器的任何连接(使用WinSCP可执行文件或我自己软件中的.NET程序集)似乎都会立即路由到用户的子目录(例如home/zild
),但文件需要上传到不同的目录(例如home/test
),用户具有足够的权限(通过WinSCP可执行文件手动执行所需的操作进行验证)。如果我尝试将远程路径设置为home/test/
或/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
似乎不是真的......
答案 0 :(得分:2)
从日志中可以清楚地看到,会话在/
开始,上传发生在/home/storage/test
。当您声称该文件实际上以/home/zild/home/storage/test
结尾时,这意味着您的FTP会话根植于/home/zild
(请注意,此路径从未在日志中看到过。)
在客户端,你无能为力。如果您需要访问FTP根目录外的文件夹,请将FTP服务器配置为不根该会话;或者使用可以访问所需文件夹的其他帐户(test
?)。