문제

I am trying to use the WinSCP .NET assembly (V5.1.7.0) for FTP protocol but I am having difficulty with file paths on the target server.

The problem is any connection to the server (using either the WinSCP executable or the .NET assembly within my own software) seems to be routed instantly to the user's subdirectory (e.g. home/zild), but the files need to be uploaded to a different directory (e.g. home/test), for which the user has sufficient permissions (verified by performing the required operations manually through the WinSCP executable). If I try to set the remote path to home/test/ or /home/test/ (the absolute path) it actually uses a relative path (e.g. home/zild/home/test) in both cases. I thought the .NET assembly only ever used absolute paths, so this is a surprise. Unfortunately I cannot find a way to set the path to the desired location (home/test).

Can somebody please explain what I am doing wrong here? I have tried searching the documentation and WinSCP forums already but remain stuck.

EDIT: Additional information

Code:

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;
}

I have not used logging yet, however if I can get that working I will post logs here too.

I have blanked out most of the file path on the local computer, however please note that it includes Japanese characters.

Finally, note that I experience the same problem with session.ListDirectory() as well.

EDIT2: Log file

. 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

The line 2013-11-18 17:26:33.152 257 "/" is the current directory appears not to be true...

도움이 되었습니까?

해결책

It's clear from the log that the session starts in / and upload takes place in /home/storage/test. As you claim that the file actually ends up in /home/zild/home/storage/test, it means that your FTP session is rooted in /home/zild (note that this path is never seen in the log).

There's nothing you can do about this on the client-side. If you need an access a folder outside your FTP root, either configure your FTP server not to root the session; or use different account (test?) that can access your desired folder.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top